@Test public void getUserByUserName() { User user = new User(); user.setUserName("tom"); user.setPassword("1234"); user.setCredit(100); doReturn(user).when(userDao).getUserByUserName("tom"); User u = userService.getUserByUserName("tom"); assertNotNull(u); assertThat(u.getUserName(), equalTo(user.getUserName())); verify(userDao, times(1)).getUserByUserName("tom"); }
public User getUserByUserName(String userName){ return userDao.getUserByUserName(userName); }
UserService { public User getUserByUserName(String userName){ return userDao.getUserByUserName(userName); } }
UserService { public User getUserByUserName(String userName){ return userDao.getUserByUserName(userName); }  }
UserService { public User getUserByUserName(String userName){ return userDao.getUserByUserName(userName); }  void register(User user); void update(User user); User getUserByUserName(String userName); User getUserById(int userId); void lockUser(String userName); void unlockUser(String userName); List<User> queryUserByUserName(String userName); List<User> getAllUsers(); void loginSuccess(User user); }
UserService { public User getUserByUserName(String userName){ return userDao.getUserByUserName(userName); }  void register(User user); void update(User user); User getUserByUserName(String userName); User getUserById(int userId); void lockUser(String userName); void unlockUser(String userName); List<User> queryUserByUserName(String userName); List<User> getAllUsers(); void loginSuccess(User user);  }