コード例 #1
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.");
 }
コード例 #2
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);
 }