class AuthenticationManagerLdapImpl extends AuthenticationManager {

    public String resetPassword(User user, String[] rnd0, String[] rnd1, String[] rnd2, String[] rnd3, String[] rnd4) {
        String changedPassword = generateRandomPassword(rnd0, rnd1, rnd2, rnd3, rnd4);
        final User userAdmin = AuthenticationManager.getDefault().getCurrentPrincipal().getUser();
        
        changePassword(user, changedPassword, userAdmin);
        activateLdapUserPasswordResetFlag(user, userAdmin);
        return changedPassword;

    }

}

class AuthenticationManagerLdapImplTest {

    private static final String PASSWORD;
    private static final String NEW_PASSWORD;
    private static final String[] RANDOM;
    private AuthenticationManagerLdapImpl sut;
    private ConfigurationUtil cfg;
    private IUserRolesService userRolesService;
    private CustomBindAuthenticator customBindAuthenticator;
    private InitialDirContextFactory initialDirContextFactory;
    private AuthenticationManagerLdapTemplate authManagerLdapTemplate;
    private ConfigurationUtil configurationUtil;
    private ApplicationContext ctx;
    private AuthenticationManager authenticationManager;
    private User user;

    @Test
    public void resetPassword() throws Exception {


        User userAdmin = getUserAdmin();

        Principal principal = mock(Principal.class);
        when(principal.getUser()).thenReturn(userAdmin);

        when(authenticationManager.getCurrentPrincipal()).thenReturn(principal);

        final String randomPassword = sut.generateRandomPassword(RANDOM, RANDOM, RANDOM, RANDOM, RANDOM);

        doNothing().when(authManagerLdapTemplate).modifyAttributes(any(DirContext.class), eq(user), any(ModificationItem[].class));

        sut.resetPassword(user, RANDOM, RANDOM, RANDOM, RANDOM, RANDOM);
        verify(authManagerLdapTemplate).changePassword(user, randomPassword, userAdmin);
        verify(authManagerLdapTemplate, times(2)).getTemplate(userAdmin);
        verify(authManagerLdapTemplate).getCallback(user, randomPassword);
        verify(authManagerLdapTemplate).getCallback(user);
        verify(authManagerLdapTemplate).changeLdapUserPassword(any(DirContext.class), eq(randomPassword), eq(user));
        verify(authManagerLdapTemplate).setLdapUserPasswordResetFlag(any(DirContext.class), eq(user));

    }

}