mardi 26 mai 2015

Mock a method without arguments but with implicit parameters

abstract trait MyApi {

  def getResult()(implicit ec: ExecutionContext): Future[String]

}

The following doesn't work:

val m = mock[MyApi]
(m.getResult _).expects() returning "..."

It fails with:

java.lang.ClassCastException: org.scalamock.MockFunction1 cannot be cast to org.scalamock.MockFunction0

Note: the example given in http://ift.tt/1SAIOMK is only useful if the method has at least one argument. So we can't use the solution as in mocking methods which use ClassTag in scala using scalamock

Aucun commentaire:

Enregistrer un commentaire