@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.");
  }
  @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.");
  }
  @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.");
  }
 @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);
 }
  @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.");
  }
 @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.");
 }
 @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);
 }
 @Test
 public void testCheckNullNewPassword() {
   editUserProfileDto.setNewUserPassword(null);
   boolean isValid = validator.isValid(editUserProfileDto, validatorContext);
   Assert.assertEquals(isValid, true, "The null password is not valid.");
 }