ExpiredPasswordBean extends AbstractPasswordBean { @Override public String changePassword() { User user = authMgr.getCurrentPrincipal().getUser(); if (user.isLdapAuthentication()) { setPasswordOld(user.getLdapPassword()); } else { setPasswordOld(user.getPassword()); } return super.changePassword(); }  @Override String changePassword(); @Override String returnError(Exception ex);  }
@Test public void shouldChangePasswordTest() throws Exception { sut.setPassword(NEW_PASSWORD); sut.setPasswordRepe(NEW_PASSWORD); user.setPasswordExpired(true); final String result = sut.changePassword(); assertThat(result, is(NavigationResults.CHANGE_PASSWORD_OK)); assertThat(user.isPasswordExpired(), is(false)); }
@Test public void givenDifferentNewPasswordsShouldSendErrorMessageTest() throws Exception { sut.setPassword(NEW_PASSWORD); sut.setPasswordRepe(NEW_PASSWORD + "INVALID"); final String result = sut.changePassword(); assertThat(result, is(nullValue())); verify(sut).addErrorMessage("error.newPasswordsNotEquals"); }
@Test public void givenSameNewPasswordsAndOldPasswordShouldSendErrorMessageTest() throws Exception { sut.setPassword(OLD_PASSWORD); sut.setPasswordRepe(OLD_PASSWORD); final String result = sut.changePassword(); assertThat(result, is(nullValue())); verify(sut).addErrorMessage("error.newPasswordEqualsOldPassword"); }