Search code examples
junitjunit4easymock

Ignore return value in EasyMock


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?


Solution

  • 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