6

I have just started to use scalatest for java code and in that we are using easymock to create mocks .

I have a situation where I want to do something like this.

expecting{
       objA.function(x$1, x$2).andReturn(objectB)
      }

For the place holder x$1,x$2 I want to call the function passing similar to something like anyObject() in java .

Kindly suggest something that could replace the placeholder.

  • I am struggling with the same. Tried `val l = mock[List[String]]; expecting { l.map(isA(classOf[String => Int])).andReturn(List(1,2,3)) } ...`, but it fails with _"2 matchers expected, 1 recorded. This exception usually occurs when matchers are mixed with raw values when recording a method"_ – Kombajn zbożowy Jul 26 '17 at 13:12

1 Answers1

0

Using methods available on Mockito (not sure if you're using it):

e.g.

def any[T : ClassTag]: T = org.mockito.Matchers.any(implicitly[ClassTag[T]].runtimeClass).asInstanceOf[T]

and you can use it as

val a = mock[Foo]
doReturn(fooResult).when(a).fooMethod(any[FooInput])
elmalto
  • 1,008
  • 1
  • 14
  • 23