我有以下的单元测试:时的Mockito - 然后返回错误
@Test
public void testGenerateFileName(){
GregorianCalendar mockCalendar = Mockito.mock(GregorianCalendar.class);
Date date = new Date(1000);
Mockito.when(mockCalendar.getTime()).thenReturn(date);
...
}
在第三行我收到以下错误:
org.mockito.exceptions.misusing.WrongTypeOfReturnValue: Date cannot be returned by getTimeInMillis() getTimeInMillis() should return long
*** If you're unsure why you're getting above error read on. Due to the nature of the syntax above problem might occur because:
1. This exception *might* occur in wrongly written multi-threaded tests. Please refer to Mockito FAQ on limitations of concurrency testing.
2. A spy is stubbed using when(spy.foo()).then() syntax. It is safer to stub spies -
- with doReturn|Throw() family of methods. More in javadocs for Mockito.spy() method.
这究竟是为什么?我没有使用getTimeInMillis()
。