I wanted to test with Mockito that a method was not called with a specific parameter type with this simplified test:
@Test
public void testEm() {
EntityManager emMock = Mockito.mock(EntityManager.class);
emMock.persist("test");
Mockito.verify(emMock, Mockito.never()).persist(Matchers.any(Integer.class));
}
Surprisingly this test failed with the following output:
org.mockito.exceptions.verification.NeverWantedButInvoked:
entityManager.persist(<any>);
Never wanted here:
-> at com.sg.EmTest.testEm(EmTest.java:21)
But invoked here:
-> at com.sg.EmTest.testEm(EmTest.java:19)
I expected this test to fail only when the persist method is called with an Integer parameter, but it fails with String as well.
Why doesn't it work and how could I test it?
Thank You.