You obviously understand that the failure is because of the different instance of WatchFolderDataVO
, so I won't go on too much about that.
There are a couple of ways to work with this, assuming you don't want to refactor to not create a new instance of WatchFolderDataVO
- Provide a matcher to the expectation.
I would suggest the EasyMock.isA()
matcher. This will make sure that the method is called with an object of the type you provide. Keep in mind, if you use one matchers, then you must use matchers for all of the parameters to the method. So your expectation would become:
sessionMock.load(EasyMock.isA(WatchFolderDataVO.class), EasyMock.eq(5));
EasyMock.expectLastCall();
Keep in mind that this will not handle nulls well. If the method is called with a null WatchFolderDataVO
then EasyMock will just fall over in a big heap.
- Use the
capture()
method and aCapture
Captures allow you to grab the object that the method is called with and make assertions on it. This can be useful if you do need to make sure that the method is called with a different (or specific) object or if you need to ensure a given state is set up before the method is called. Again, the capture()
method is a matcher, so you must use matchers for all of the parameters to the method, so your expectation would look like this:
Capture<WatchFolderDataVO> watchFolderDataCapture = new Capture<WatchFolderDataVO>();
sessionMock.load(EasyMock.capture(watchFolderDataCapture ), EasyMock.eq(5));
EasyMock.expectLastCall();
//The rest of your test
//You can then do tests like the following
WatchFolderDataVO capturedValue = watchFolderDataCapture .getValue();
assertNotSame(capturedValue, watchFolderDataVO);