I have in my unit test the following line
verify(MyMock).handleError(any(ICallBack.class),any(BaseError.class) );
But what I want to write is a verify that tests if the base error class (2nd parameter) has
BaseError::errorCode = 3
How do I do it?
Is it only with argument capture?
Thanks.
Just use an appropriate matcher for the second argument. For example:
verify(MyMock).handleError(any(ICallBack.class), eq(new BaseError(3)));
assuming that this instance would be equal to any BaseError
instance with this error code. You can also implement a custom ArgumentMatcher<BaseError>
and implement the logic where you return true
if the given instances errorCode
is 3
e.g. by:
verify(MyMock).handleError(any(ICallBack.class),
argThat(new ArgumentMatcher<BaseError> {
@Override
public boolean matches(Object baseError) {
return ((BaseError) baseError).errorCode == 3;
}
}));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With