title: Regular unit tests pass but Mockito all fail
body: <p>this simple mockito is failing I do not know why? I suspect set up is not complete?
  When I replace userService  by userDAO in the test method it passes, why this happen?</p>
  <pre><code>public class UserServiceTest {
  
  private static IUserService userService;
  private static IUserDAO userDAO;
  
  private User GENERIC_EMPLOYEE_1;
  
  
  @BeforeClass
  public static void setUpBeforeClass() throws Exception {
      userService = new UserService();
      userDAO = mock(IUserDAO.class);
      
  }
  
  @Before
  public void setUp() throws Exception {
      
      GENERIC_EMPLOYEE_1 = new User(1, &quot;genericEmployee1&quot;, &quot;genericPassword&quot;, Role.EMPLOYEE);
     
    }
  
  @Test
  public void testGetByUsernamePassesWhenUsernameExists() {
      //Optional&lt;User&gt; u=userDAO.create(GENERIC_EMPLOYEE_1);
      //assertEquals(u.get().getUsername(),&quot;genericEmployee1&quot;);
     when(userDAO.getByUsername(anyString())).thenReturn(Optional.of(GENERIC_EMPLOYEE_1));
  
      assertEquals(Optional.of(GENERIC_EMPLOYEE_1),
              userService.getByUsername(GENERIC_EMPLOYEE_1.getUsername()));
  
      verify(userDAO).getByUsername(GENERIC_EMPLOYEE_1.getUsername());
  }
  </code></pre>
  <p>}</p>