I see a few issues here. First of all, you’re apparently wondering why Mockito is complaining about your “verify().equals()” call. The error message that that you provided here should have explained that: “you verify either of: final/private/equals()/hashCode() methods”. This doesn’t solve your problem, but outside of refactoring your “equals()” method or simply removing the test, there’s no alternative I’m aware of.
I hope you were intending to write more in the “testEquals” method than that verification. It doesn’t make sense by itself, even if it worked.
It’s not a good idea to initialize your mocks in a “@BeforeClass” method. Initialize them as normal instance variables, or perhaps in a “@Before” method. Each test method runs with a fresh instance of the test class, it’s best to not do any “@BeforeClass” work unless it’s absolutely necessary.
It’s really odd to get the data you’re using to verify against from another instance of the same class under test. Not a good idea.
--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
mockito+u...@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at http://groups.google.com/group/mockito.
To view this discussion on the web visit
https://groups.google.com/d/msgid/mockito/d8f77f8b-5114-4d9a-afc9-a19ecdc05ea8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Ashok,
David is right, there’s some issues in the code snippet here. As he rightly pointed out the cause is in the message
... final/private/equals()/hashCode() methods.
Those methods *cannot* be stubbed/verified.
equals
method stubbing is not supported, you can see more in the FAQ wiki : https://github.com/mockito/mockito/wiki/FAQ
While all point of David are correct, I’d like to add that this code is mocking value type, one should not mock value object, instead create factory or builders to create concrete object to test actual behavior. Mocks are better suited for test interactions between different objects that collaborate together.
Here’s a page here that gives more tips to write good tests : https://github.com/mockito/mockito/wiki/How-to-write-good-tests
Hope that helps.
— Brice
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/B8D164BED956C5439875951895CB4B223BEE8746%40CAFRFD1MSGUSRIA.ITServices.sbc.com.