コード例 #1
0
  @Test
  public void emptyEmailShouldBeValidBecauseItIsNotBusy() {
    EditUserProfileDto editedUserProfile = new EditUserProfileDto();
    editedUserProfile.setEmail(null);
    boolean isValid = validator.isValid(editedUserProfile, validatorContext);

    assertTrue(isValid, "Empty email should be valid, becuase it isn't busy.");
  }
コード例 #2
0
  @Test
  public void changedEmailShouldBeValidIfItIsNotBusy() {
    EditUserProfileDto editedUserProfile = new EditUserProfileDto();
    editedUserProfile.setEmail("*****@*****.**");

    boolean isValid = validator.isValid(editedUserProfile, validatorContext);

    assertTrue(isValid, "New email isn't taken, so it must be valid.");
  }
コード例 #3
0
  @Test
  public void notChangedEmailShouldBeValid() {
    EditUserProfileDto editedUserProfile = new EditUserProfileDto();
    editedUserProfile.setEmail(userEmail);

    boolean isValid = validator.isValid(editedUserProfile, validatorContext);

    assertTrue(isValid, "Email of current user isn't valid.");
  }
コード例 #4
0
 @BeforeMethod
 public void init() {
   MockitoAnnotations.initMocks(this);
   Mockito.when(userService.getCurrentUser())
       .thenReturn(new JCUser("username", "email", userCurrentPassword));
   validator = new ChangedPasswordValidator(userService, encryptionService);
   //
   editUserProfileDto.setCurrentUserPassword(userCurrentPassword);
   editUserProfileDto.setNewUserPassword(userNewPassword);
 }
コード例 #5
0
  @Test
  public void changedEmailShouldNotBeValidIfItIsBusy() {
    when(userDao.getByEmail(anyString()))
        .thenReturn(new JCUser("*****@*****.**", "email", "password"));
    EditUserProfileDto editedUserProfile = new EditUserProfileDto();
    editedUserProfile.setEmail("*****@*****.**");
    when(validatorContext.buildConstraintViolationWithTemplate(null)).thenReturn(violationBuilder);
    when(violationBuilder.addNode(anyString())).thenReturn(nodeBuilderDefinedContext);

    boolean isValid = validator.isValid(editedUserProfile, validatorContext);

    assertFalse(isValid, "New email is taken, so it must be invalid.");
  }
コード例 #6
0
 @Test
 public void testChangeUserPasswordCorrect() {
   String currentUserPassword = editUserProfileDto.getCurrentUserPassword();
   Mockito.when(encryptionService.encryptPassword(currentUserPassword))
       .thenReturn(currentUserPassword);
   boolean isValid = validator.isValid(editUserProfileDto, validatorContext);
   Assert.assertEquals(isValid, true, "The old password is correct, but the check fails.");
 }
コード例 #7
0
 @Test
 public void testChangeUserPasswordIncorrect() {
   String incorrectCurrentPassword = "******";
   editUserProfileDto.setCurrentUserPassword(incorrectCurrentPassword);
   Mockito.when(encryptionService.encryptPassword(incorrectCurrentPassword))
       .thenReturn(incorrectCurrentPassword);
   Mockito.when(validatorContext.buildConstraintViolationWithTemplate(null))
       .thenReturn(violationBuilder);
   Mockito.when(violationBuilder.addNode(Mockito.anyString()))
       .thenReturn(nodeBuilderDefinedContext);
   boolean isValid = validator.isValid(editUserProfileDto, validatorContext);
   Assert.assertEquals(isValid, false, "The old password isn't correct, but the check passed.");
   Mockito.verify(validatorContext).buildConstraintViolationWithTemplate(null);
 }
コード例 #8
0
 @Test
 public void testCheckNullNewPassword() {
   editUserProfileDto.setNewUserPassword(null);
   boolean isValid = validator.isValid(editUserProfileDto, validatorContext);
   Assert.assertEquals(isValid, true, "The null password is not valid.");
 }