### Question:
AmbariLdapDataPopulator { protected void cleanUpLdapUsersWithoutGroup() throws AmbariException { final List<User> allUsers = users.getAllUsers(); for (User user : allUsers) { if (user.isLdapUser() && user.getGroups().isEmpty()) { users.removeUser(user); } } } @Inject  AmbariLdapDataPopulator(Provider<AmbariLdapConfiguration> configurationProvider, Users users); boolean isLdapEnabled(); LdapSyncDto getLdapSyncInfo(); LdapBatchDto synchronizeAllLdapGroups(LdapBatchDto batchInfo); LdapBatchDto synchronizeAllLdapUsers(LdapBatchDto batchInfo); LdapBatchDto synchronizeLdapGroups(Set<String> groups, LdapBatchDto batchInfo); LdapBatchDto synchronizeLdapUsers(Set<String> users, LdapBatchDto batchInfo); LdapBatchDto synchronizeExistingLdapGroups(LdapBatchDto batchInfo); LdapBatchDto synchronizeExistingLdapUsers(LdapBatchDto batchInfo);  }### Answer:
@Test @SuppressWarnings({ "serial", "unchecked" }) public void testCleanUpLdapUsersWithoutGroup() throws AmbariException { final Provider<AmbariLdapConfiguration> configurationProvider = createNiceMock(Provider.class); final AmbariLdapConfiguration configuration = createNiceMock(AmbariLdapConfiguration.class); final Users users = createNiceMock(Users.class); expect(configurationProvider.get()).andReturn(configuration).anyTimes(); final GroupEntity ldapGroup = new GroupEntity(); ldapGroup.setGroupId(1); ldapGroup.setGroupName("ldapGroup"); ldapGroup.setGroupType(GroupType.LDAP); ldapGroup.setMemberEntities(new HashSet<>()); final User ldapUserWithoutGroup = createLdapUserWithoutGroup(); final User ldapUserWithGroup = createLdapUserWithGroup(ldapGroup); final User localUserWithoutGroup = createLocalUserWithoutGroup(); final User localUserWithGroup = createLocalUserWithGroup(ldapGroup); final List<User> allUsers = new ArrayList<User>() { { add(ldapUserWithoutGroup); add(ldapUserWithGroup); add(localUserWithoutGroup); add(localUserWithGroup); } }; expect(users.getAllUsers()).andReturn(new ArrayList<>(allUsers)); final List<User> removedUsers = new ArrayList<>(); final Capture<User> userCapture = EasyMock.newCapture(); users.removeUser(capture(userCapture)); expectLastCall().andAnswer(new IAnswer<Void>() { @Override public Void answer() throws Throwable { removedUsers.add(userCapture.getValue()); allUsers.remove(userCapture.getValue()); return null; } }); replay(users, configurationProvider, configuration); final AmbariLdapDataPopulatorTestInstance populator = new AmbariLdapDataPopulatorTestInstance(configurationProvider, users); populator.setLdapTemplate(createNiceMock(LdapTemplate.class)); populator.setLdapServerProperties(createNiceMock(LdapServerProperties.class)); populator.cleanUpLdapUsersWithoutGroup(); assertEquals(removedUsers.size(), 1); assertEquals(allUsers.size(), 3); assertTrue(allUsers.contains(ldapUserWithGroup)); assertTrue(allUsers.contains(localUserWithoutGroup)); assertTrue(allUsers.contains(localUserWithGroup)); assertEquals(removedUsers.get(0), ldapUserWithoutGroup); verify(users); }