この質問は私が知っていることは明らかですが、ドキュメントに書かれていることはすべて試しましたが、どのクラスでも単一のメソッドをモックすることはできません。
このテストでは、Scala 2.10 および ScalaTest 2 用の scalaMock 3 を使用しています。
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)))
}
}
これは私にとってはかなり単純に思えますが、期待はこのエラーを投げることです
type mismatch; found : Option[org.joda.time.DateTime] required: ? ⇒ ?
ここで何か間違ったことをしていますか?メソッドの期待値を設定する別の方法はありますか?