mercredi 22 avril 2015

Are any[Param] and Param(anyInt) equivalent while stubbing in Scala Spec2?

I'm having a strange behaviour while stubbing method that takes case classes as parameters.

I'm still trying to understand why, but in one case I'm getting a

You cannot use argument matchers outside of verification or stubbing. Examples of correct usage of argument matchers: when(mock.get(anyInt())).thenReturn(null); doThrow(new RuntimeException()).when(mock).someVoidMethod(anyObject()); verify(mock).someMethod(contains("foo"))

When stubbing like this

simpleTrait.anotherMethod(any[Param]) returns "Mock String"

and I have to change it like this

simpleTrait.anotherMethod(Param(anyInt)) returns "Mock String"

Where

case class Param(val: Int)

and

trait SimpleTrait { def anotherMethod(someParam: Param): String }

Both the behaviour seems equivalent, though.

Any Ideas?

Aucun commentaire:

Enregistrer un commentaire