I'm new to Mockito and trying to understand why my unit test passes
after trying to force it to fail. I'm only doing this to learn more
about Mockito.
I have a POJO that i wish to test:
public class EmployeeCreatedEventHandler {
@Autowired
private TimberlineEmployeeService timberlineEmployeeService;
public void handle(EmployeeCreatedEvent event) throws
CreateTimberlineEmployeeException {
//
// Create Timberlne Employee record
//
timberlineEmployeeService.createTimberlineEmployee(event.getEmployee());
}
}
My test class:
@RunWith(MockitoJUnitRunner.class)
public class EmployeeCreatedEventHandlerTest {
@Mock
private TimberlineEmployeeService mockTimberlineEmployeeService;
@InjectMocks
private EmployeeCreatedEventHandler handler = new
EmployeeCreatedEventHandler();
@Test
public void testHandle() {
EmployeeCreatedEvent mockEvent = mock(EmployeeCreatedEvent.class);
handler.handle(mockEvent);
verify(mockTimberlineEmployeeService,
times(2)).createTimberlineEmployee(mockEvent.getEmployee());
}
}
I'm trying to force the test to fail by verifying that the
mockTimberlineEmployeeService will call the createTimberlineEmployee
method twice (times(2)) but it does not fail, it passes with green
bars.
However, i was able to make the test fail after changing the argument
to the createTimberlineEmployee method like so:
verify(mockTimberlineEmployeeService,
times(2)).createTimberlineEmployee(any(EmployeeType.class));
Can anybody tell me why?
--
You received this message because you are subscribed to the Google Groups "mockito" group.
To post to this group, send email to
moc...@googlegroups.com.
To unsubscribe from this group, send email to
mockito+u...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/mockito?hl=en.