title: Mocking a return value
body: <p>I am using Mockito 1.9.5 to try and test a method. Here is the method: </p>
  
  <pre><code>@Autowire
  AuditLogRepository auditlogRepository;
  
  //method stuff abbreviated out
  
  if (authentic.isAuthorized()) {
      menuService.updateUserWithMenu( authentic );
      AuditLog auditor = Helper.buildAuditor( authentic );
      auditor.setAccessPoint( request.getRequestURL().toString() );
      ....
      AuditLog createdAuditLog = auditlogRepository.save( auditor );
      logger.debug( "Created AuditLog id = " + createdAuditLog.getID() );
      ...
  
  }
  </code></pre>
  
  <p>And here is how I am trying to test it:</p>
  
  <pre><code>@InjectMocks
  LoginController loginController;
  
  @Mock
  AuditLog aLog;
  
  @Mock
  AuditLog createdAuditLog;
  
  @Mock
  AuditLogRepository auditlogRepositoryMock;
  
  @Before
  public void setUp() {
      MockitoAnnotations.initMocks( this );
      this.mockMvc = MockMvcBuilders.standaloneSetup( loginController ).build();
  }
  
  @Test    
  public void testLogin() throws Exception {
      ...
      AuditLog aLog = mock( AuditLog.class );
      when( auditlogRepositoryMock.save( aLog ) ).thenReturn(createdAuditLog );
      when( createdAuditLog.getID() ).thenReturn( new Long( 1 ) );
  </code></pre>
  
  <p>It looks like no matter what I do, Mockito will always return null, except for primitives.  But my code is going to act upon a returned value.  So my question is there a way to test this without getting the null pointer?  Can Mockito return an object from a method call?</p>