@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;
    }
}