Reputation: 551
I have the following expectation in a JUnit test class:
CustomEvent myCustomEvent = new CustomEvent(data1, data2);
m_context.checking(new Expectations() {{
oneOf(handler).somethingHappened(myCustomEvent); }});
In the class that is being tested, I am calling handler.somethingHappened
with an instance of CustomEvent
using the same arguments in the test class. However JMock claims an unexpected invocation when this occurs in the class being tested.
The JMock error shows a difference object reference to the one that was created in the class, so I'm assuming this is why I am having the unexpected reference.
My question is, how can I change my expectation so that I can test that the objects are actually equal? Equal being the contents of the object rather the memory reference.
Thanks
Upvotes: 1
Views: 141
Reputation: 2707
how is myCustomEvent
related to the one that appears in the code during the test? The default match is to call equals()
, otherwise you should use a matcher to describe that relationship (and don't forget the with
clause)
Upvotes: 1