You're using a matcher where you should to use an actual object.
EasyMock.expect(premium.getCommencementDate()).andReturn(EasyMock.anyObject(Date.class)).anyTimes();
In the line above, you have used the anyObject()
matcher where you really mean to use a Date
object.
I wonder if you are confusing matchers with mocks in this sense. The anyObject()
matcher is a way of confirming that the method you have mocked is called with an object of type Date
. It does not create a date object that can be used as an instance of the Date
class. For that you would need to create a mock instance of Date
. So, keep in mind that matchers should be used as parameters to mocked methods, but not as return values.
The below expectations will fix your issue:
Date mockDate = EasyMock.createMock(Date.class);
final IPremium premium = EasyMock.createMock(IPremium.class);
EasyMock.expect(premium.getCommencementDate()).andReturn(mockDate).anyTimes();
expect(
premium.getRemainingPremium(
(BigDecimal) EasyMock.anyObject(),
(Date) EasyMock.anyObject(),
(Date) EasyMock.anyObject(),
EasyMock.anyBoolean()
))
.andReturn(BigDecimal.TEN).anyTimes();
replay(premium);