DefaultUserDao implements UserDao { @Override public User getUserByLogin(final String login) { String querySql = QUERY; Map<String, Object> parameters = Collections.<String, Object>singletonMap("login", login); Query<User> query = new Query<User>(User.class, querySql, parameters); return persistenceManager.getSingleResult(query); }  @Override User getUserByLogin(final String login); void setPersistenceManager(PersistenceManager<User, Long> persistenceManager);  }
@Test public void testGetUserByLogin() throws Exception { String login = "login"; User expected = new User(); expected.setLogin(login); String querySql = "SELECT u FROM User u WHERE u.login=:login"; Map<String, Object> parameters = Collections.<String, Object>singletonMap("login", login); Query<User> query = new Query<User>(User.class, querySql, parameters); when(persistenceManager.getSingleResult(Matchers.<Query<User>>any())).thenReturn(expected); User actual = unit.getUserByLogin(login); verify(persistenceManager).getSingleResult(query); assertEquals(expected, actual); }