The method I want to test calls the 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 the MethodToTest method really calls these methods with exactly these arguments. This is the code I wrote:
@Test public void myMockTest(){ oneOf(mock).doSomething(1); oneOf(mock).doSomething(2); oneOf(mock).doSomething(3); }
In (2) I get an "Unexpected call" - as if he could not distinguish between different arguments. So I tried this:
exactly(3).of(mock).doSomething(with(Matchers.anyOf(same(1), same(2), same(3))));
But that also did not do what I expected.
Finally, it worked:
exactly(3).of(mock).doSomething(with(any(Integer.class)));
So, I know that my method has been called 3 times with any Integer. Is there any way to make sure that the argument (s) that I passed is exactly ?
source share