Question

We try to verify the behaviour of an action with Mockito. The test code looks like this

final Type1 mock = mock(Type1.class);
new SomeAction<Type1>(mock).actionPerformed(null);

verify(mock).someMethod();

The method actionPerformed contains just the call of someMethod on the object provided in the constructor of Type1. Yet Mockito complains that the expected method call did not happen, instead a different method call happened. But the String representation of the two calls printed by Mockito are exactly the same!

Any explanation what is going on?

Update: ErrorMessage from Mockito

Argument(s) are different! Wanted:
type1.someMethod();
-> at xxx
Actual invocation has different arguments:
type1.someMethod();
-> at xxx
Was it helpful?

Solution

This is a bit of a stretch, but check your toString implementations. I've ran into some irritating unit test scenarios where the expected and observed appeared to be the same from the unit test point of view when in reality they were different. In the end it was a variation in toString that caused me to believe there was a similarity when in reality there was not.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top