Ola,
I'm busy writing a unit test like
monitor.severe(mock(MonitorEventType.class), anyString());
When I execute this I get:
Invalid use of argument matchers.
0 matchers expected, 1 recorded.
So I tried:
monitor.severe(mock(MonitorEventType.class), eq(anyString()));
But this gave
Invalid use of argument matchers.
0 matchers expected, 2 recorded.
I also tried to use
monitor.severe(any(MonitorEventType.class), anyString());
but this gives a null pointer.
What works is
monitor.severe(mock(MonitorEventType.class), "");
But thats not what I want.
My testMethod is :
@Test
public void testSevere() {
monitor.severe(mock(MonitorEventType.class), eq(anyString()));
ArgumentCaptor<DefaultMonitoringEventImpl> captor = ArgumentCaptor.forClass(DefaultMonitoringEventImpl.class);
verify(event).fire(captor.capture());
DefaultMonitoringEventImpl input = captor.getValue();
assertThat(fetchMonitorLevel(input), equalTo(MonitorEventLevel.SEVERE.getDescription()));
}
private String fetchMonitorLevel(DefaultMonitoringEventImpl input) {
Map<String, String> map = input.getMonitorEventWaardes().getWaardenLijst();
return map.get(MonitorEvent.MONITOR_EVENT_LEVEL_KEY);
}
And the method under test is:
public void severe(MonitorEventType type, String message) {
write(type, MonitorEventLevel.SEVERE, message, null);
}
@Asynchronous
public void write(MonitorEventType type, MonitorEventLevel level, String message, MonitorEventWaardes pEventWaardes) {
event.fire(new DefaultMonitoringEventImpl(type, level, message, pEventWaardes));
}
What I want is that When I call monitor.severe with a random MonitorEventType and a random String that the "level" parameter in teh event.fire call is filled with the right value.