The method I want to test is calling a mock method with different arguments:
public void methodToTest(){
getMock().doSomething(1);
getMock().doSomething(2);
getMock().doSomething(3);
}
In my unit test I want to know, if methodToTest really is calling those methods with exactly those arguments. This is the code I wrote:
@Test
public void myMockTest(){
oneOf(mock).doSomething(1);
oneOf(mock).doSomething(2);
oneOf(mock).doSomething(3);
}
At (2) I get an "Unexpected invocation" - as if it couldn't distinguish different arguments. So I've tried that one:
exactly(3).of(mock).doSomething(with(Matchers.anyOf(same(1), same(2), same(3))));
But this also didn't do what I've expected.
Finally, this one worked:
exactly(3).of(mock).doSomething(with(any(Integer.class)));
So I know, that my method was called 3 times with any Integer number. Is there any way to make sure, it's exactly the argument(s) I have passed?