1

This question seems pretty obvious I know, but i've tried everything that is written on the documentation and I cant't mock a single method on any classes.

For this test, I am using scalaMock 3 for Scala 2.10 and ScalaTest 2

DateServiceTest.scala

@RunWith(classOf[JUnitRunner])
class DateServiceTest extends FunSuite with MockFactory{
  val conf = new SparkConf().setAppName("Simple Application").setMaster("local")

  val sc = new SparkContext(conf)

  implicit val sqlc = new SQLContext(sc)

  val m = mock[DateService]
  (m.getDate _).expects().returning(Some(new DateTime)) // Error here
}

DateService.scala

class DateService extends Serializable {

  def getDate(implicit sqlc: SQLContext): Option[DateTime] = {
    Some(new DateTime(loadDateFromDatabase(sqlc)))
  }
}

This seems pretty simple for me, but the expectation is Throwing me this error

type mismatch; found : Option[org.joda.time.DateTime] required: ? ⇒ ?

Am I doing something wrong here? Is there another way to set the expectations of a method ?

Will
  • 2,057
  • 1
  • 22
  • 34

1 Answers1

0

Your getDate method expects a SQLContext - try adding a wildcard (*) or pass the particular sqlc:

(m.getDate _).expects(*).returning(Some(new DateTime))
// Or, alternatively
(m.getDate _).expects(sqlc).returning(Some(new DateTime))
Sean Vieira
  • 155,703
  • 32
  • 311
  • 293