AuthenticationManagerLdapTemplate { protected void modifyAttributes(DirContext dirContext, User user, ModificationItem[] mods) throws NamingException { dirContext.modifyAttributes(user.getLdapName(), mods); }  void changePassword(final User user, final String password);  }
@Test public void shouldApplyUpdate() throws NamingException { assertThat(user.isPasswordExpired(), is(Boolean.TRUE)); assertThat(user.getLdapPassword(), is(PASSWORD)); Attribute newPasswordAttribute = new BasicAttribute("userPassword", NEW_PASSWORD); ModificationItem[] mods = new ModificationItem[1]; mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, newPasswordAttribute); try { dirContext.modifyAttributes(user.getLdapName(), mods); } catch (NamingException e) { AuthenticationManagerLdapImpl.log.error(e); throw e; } user.setPasswordExpired(Boolean.FALSE); user.setLdapPassword(NEW_PASSWORD); assertThat(user.isPasswordExpired(), is(Boolean.FALSE)); assertThat(user.getLdapPassword(), is(NEW_PASSWORD)); }
@Test(expected = NamingException.class) public void shouldThrowNamingExceptionWhenApplyUpdate() throws NamingException { user.setPasswordExpired(Boolean.FALSE); doThrow(new NamingException()).when(dirContext).modifyAttributes(eq(user.getLdapName()), any(ModificationItem[].class)); assertThat(user.isPasswordExpired(), is(Boolean.FALSE)); assertThat(user.getLdapPassword(), is(PASSWORD)); try { Attribute newPasswordAttribute = new BasicAttribute("userPassword", NEW_PASSWORD); ModificationItem[] mods = new ModificationItem[1]; mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, newPasswordAttribute); try { dirContext.modifyAttributes(user.getLdapName(), mods); } catch (NamingException e) { AuthenticationManagerLdapImpl.log.error(e); throw e; } user.setPasswordExpired(Boolean.FALSE); user.setLdapPassword(NEW_PASSWORD); } catch (NamingException e) { assertThat(user.isPasswordExpired(), is(Boolean.FALSE)); assertThat(user.getLdapPassword(), is(PASSWORD)); throw e; } }