Exemple #1
0
  @Test
  public void updateUser() {
    // 如果明文密码不为空,加密密码会被更新.
    User user = UserData.randomNewUser();
    accountService.updateUser(user);
    assertNotNull(user.getSalt());

    // 如果明文密码为空,加密密码无变化。
    User user2 = UserData.randomNewUser();
    user2.setPlainPassword(null);
    accountService.updateUser(user2);
    assertNull(user2.getSalt());
  }
Exemple #2
0
  @Test
  public void registerUser() {
    User user = UserData.randomNewUser();
    Date currentTime = new Date();
    accountService.setDateProvider(new ConfigurableDateProvider(currentTime));

    accountService.registerUser(user);

    // 验证user的角色,注册日期和加密后的密码都被自动更新了。
    assertEquals("user", user.getRoles());
    assertEquals(currentTime, user.getRegisterDate());
    assertNotNull(user.getPassword());
    assertNotNull(user.getSalt());
  }