0

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

Now I want to verify something like this:

verify(event).fire(
   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.

-Bgvv1983

Bgvv1983
  • 1,256
  • 1
  • 13
  • 27

1 Answers1

2

Use ArgumentCaptor:

ArgumentCaptor<DefaultMonitoringEventImpl> captor = ArgumentCaptor.forClass(DefaultMonitoringEventImpl.class);
Mockito.verify(event).fire(captor.capture());
DefaultMonitoringEventImpl actual = captor.getValue();
Assert.assertEquals(MonitorEventLevel.ALL, actual.getMonitorEventLevel());
Mykhailo
  • 1,134
  • 2
  • 17
  • 25
  • Thank, stupid I haven't thought of that. One little remark on your solution though. Mockito.verify(event).fire(captor); must be: Mockito.verify(event).fire(captor.capture()); – Bgvv1983 Oct 21 '16 at 11:54