What's the purpose of Custom Matcher and how we can compare with
Object.equal().
I have a problem that Object.equal()
solve easily while passing parameters in when()
but some time I need to use Matchers. I need to know what would be the behavior and how it would be executed.
My current code is:
@Test
public void myTest() {
when(service.foo(xyzService, new ARequest(1, "A"))).thenReturn(new AResponse(1, "passed"));
when(service.foo(xyzService, new ARequest(2, "2A"))).thenReturn(new AResponse(2, "passed"));
when(service.foo(xyzService, new BRequest(1, "B"))).thenReturn(new BResponse(112, "passed"));
c.execute();
}
currently it works fine but in my actual business case i am not able to mock xyzService
it a method level variable. I want o use any()
instead of xyzService
. but in this case everything brokers.