0

How do I have EasyMock to test that a method is called and returns a specific type - irrespective of the value viz

EasyMock.expect(........).andReturn(String.Type).times(5);

I just need to ensure that a method is called x number of times.
Is this possible?

IUnknown
  • 9,301
  • 15
  • 50
  • 76

2 Answers2

0

With EasyMock you have to specify the behaviour of the method call. If the value of the return value doesn't matter then you can return a dummy value. Afterwards you can verify that the mock was called like you expected it to be called.

expect(mock.doSomething(...)).andReturn("dummy value").times(5);
replay(mock);
...
verify(mock);
Henri
  • 5,551
  • 1
  • 22
  • 29
Stefan Birkner
  • 24,059
  • 12
  • 57
  • 72
  • 1
    You are right, the verify is needed and that's it. However, his original syntax is preferred. `expect(mock.foo()).andReturn(null).times(5)` – Henri Dec 30 '17 at 05:20
0

You can use either EasyMock.isA(< TypeObj >) or EasyMock.anyObject(< TypeObj >). See below for sample code

expect(mock.doSomething(...)).andReturn(EasyMock.isA(String.class)).times(5); replay(mock); ... verify(mock);

Check the Here for more details

Sravya
  • 149
  • 5