对DAO编写单元测试[3]

发表于:2010-04-26来源:作者:点击数: 标签:单元DAOdao编写
对DAO编写 单元测试 [3] 软件测试 } UserDao接口定义了对用户的相关操作: public interface UserDao { User queryForSignOn(String username); User queryUser(String username); void createUser(User user); void updateUser(User user); boolean updateE

   对DAO编写单元测试[3]   软件测试 

    }  

  UserDao接口定义了对用户的相关操作:

  public interface UserDao {

  User queryForSignOn(String username);

  User queryUser(String username);

  void createUser(User user);

  void updateUser(User user);

  boolean updateEmailValidation(String username, int ticket);

  String createPasswordTicket(User user);

  boolean updatePassword(String username, String oldPassword, String newPassword);

  boolean queryResetPassword(User user, String ticket);

  boolean updateResetPassword(User user, String ticket, String password);

  void updateLock(User user, long lockTime);

  void updateUnlock(User user);

  }

  UserDaoImpl是其实现类:

  public class UserDaoImpl implements UserDao {

  public User queryForSignOn(String username) {

  User user = queryUser(username);

  if(user.getLocked())

  throw new LockException(user.getLockDate());

  return user;

  }

  public User queryUser(String username) {

  return (User) HibernateUtil.query(User.class, username);

  }

  public void createUser(User user) {

  user.setEmailValidation((int)(Math.random() * 1000000) + 0xf);

原文转自:http://www.ltesting.net