Beispiel #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());
  }
Beispiel #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());
  }
Beispiel #3
0
  @Test
  public void deleteUser() {
    // 正常删除用户.
    accountService.deleteUser(2L);
    Mockito.verify(mockUserDao).delete(2L);

    // 删除超级管理用户抛出异常, userDao没有被执行
    try {
      accountService.deleteUser(1L);
      fail("expected ServicExcepton not be thrown");
    } catch (ServiceException e) {
      // expected exception
    }
    Mockito.verify(mockUserDao, Mockito.never()).delete(1L);
  }