title: mockito when - then return error
body: <p>I have the following unit test:</p>
  
  <pre><code>@Test
  public void testGenerateFileName(){
  
  GregorianCalendar mockCalendar = Mockito.mock(GregorianCalendar.class);
  Date date = new Date(1000);
  Mockito.when(mockCalendar.getTime()).thenReturn(date);  
  ...
  }
  </code></pre>
  
  <p>At the third line I am getting the following error:</p>
  
  <pre><code>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.
  </code></pre>
  
  <p>Why is this happening? I'm not using <code>getTimeInMillis()</code>.</p>