1

I have a method that I am trying to verify is called once with specific arguments, but I don't care if the method is called any other number of times with different arguments. How can I do this in Mockito.

For example:

obj.method("example", example); // expected
obj.method("example1", example2); // indifferent 
obj.method("example", example); // unexpected 
verify(obj).method("example", example); // will pass
asked Mar 17, 2016 at 14:57
1
  • 1
    I would not expect example2 to have any influence on your verify there, unless example.equals(example2). For example, assume x.doSomething("a"); x.doSomething("b"); -> Mockito.verify(x).doSomething("a"); - works, while if we added x.doSomething(new String("a"); it would not work. Commented Mar 17, 2016 at 15:59

1 Answer 1

1
verify(obj).method("example", example); // will pass 

The indifferent code will not cause verify to fail.

My issue was that the expected line was not being executed and the indifferent showed up as different from what was expected after the unit test ran. Causing me to believe the expected line ran and the indifferent line to cause the failure.

answered Mar 17, 2016 at 17:25
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.