简体   繁体   中英

JMock Expecting Custom Class

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM