Bgvv1983 Bgvv1983 - 1 year ago 159
Java Question


I'm busy with writing a Junit test with Mockito.

Now I want to verify something like this:

new DefaultMonitoringEventImpl(
any(Class.class), any(MonitorEventType.class), MonitorEventLevel.ALL, anyString()

I only care about the third parameter.
when I try this I get a: InvalidUseOfMatchersException.

Whatever i try it wont fix this issue.
Related topics won's give a satisfied solution.


Answer Source

Use ArgumentCaptor:

ArgumentCaptor<DefaultMonitoringEventImpl> captor = ArgumentCaptor.forClass(DefaultMonitoringEventImpl.class);
DefaultMonitoringEventImpl actual = captor.getValue();
Assert.assertEquals(MonitorEventLevel.ALL, actual.getMonitorEventLevel());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download