예제 #1
0
  @Test
  public void testVerificationToken() {
    SecurityTools securityTools = Mockito.mock(SecurityTools.class);
    when(securityTools.generateRandomString(Mockito.anyInt())).thenReturn("TOKEN");

    UserTools userTools = new UserTools();
    userTools.setSecurityTools(securityTools);

    User user = new User("*****@*****.**", "12345");
    userTools.generateVerificationToken(user);

    assertNotNull(user.getVerificationToken());
    assertFalse(user.getVerificationToken().isEmpty());
  }
예제 #2
0
  @Test
  public void testEncryptPasssword() {
    String plainTextPassword = "******";

    SecurityTools securityTools = Mockito.mock(SecurityTools.class);
    when(securityTools.generateRandomString(Mockito.anyInt())).thenReturn("SALT");

    UserTools userTools = new UserTools();
    userTools.setSecurityTools(securityTools);

    User user = new User("*****@*****.**", plainTextPassword);
    userTools.encryptPasssword(user);

    assertEquals(user.getSalt(), "SALT");
    assertNotNull(user.getPassword());
    assertFalse(user.getPassword().isEmpty());
    assertNotEquals(plainTextPassword, user.getPassword());
  }