I am trying to mock the return of GregorianCalendar.getTime() which should be a Date(). But am getting this error
org.mockito.exceptions.misusing.WrongTypeOfReturnValue:
Date$$EnhancerByMockitoWithCGLIB$$91e3d4b7 cannot be returned by getTimeInMillis()
getTimeInMillis() should return long
Mockito.when(gregorianCalendar.getTime()).thenReturn(date);
Both gregorianCalendar and date are mocked objects.
Any advice on how to fix this? All help much appreciated
Take a look on implementation of getTime()
that is located in super class of GregorianCalendar
named Calendar
:
public final Date getTime() {
return new Date(getTimeInMillis());
}
This means that you should probably try to mock getTimeInMillis()
instead:
Mockito.when(gregorianCalendar.getTimeInMillis()).thenReturn(date.getTime());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With