### Question:
UserSyncService { @VisibleForTesting void removeUsersFromGroups(FreeIpaClient freeIpaClient, Multimap<String, String> groupMapping, BiConsumer<String, String> warnings) throws FreeIpaClientException { for (String group : groupMapping.keySet()) { for (List<String> users : Iterables.partition(groupMapping.get(group), maxSubjectsPerRequest)) { LOGGER.debug("removing users {} from group {}", users, group); try { RPCResponse<Group> groupRemoveMembersResponse = freeIpaClient.groupRemoveMembers(group, users); List<String> members = Optional.ofNullable(groupRemoveMembersResponse.getResult().getMemberUser()).orElse(List.of()); if (Collections.disjoint(members, users)) { LOGGER.debug("Successfully removed users {} from {}", users, groupRemoveMembersResponse.getResult()); } else { LOGGER.error("Failed to remove {} from group '{}': {}", users, group, groupRemoveMembersResponse.getFailed()); warnings.accept(group, String.format("Failed to remove users from group: %s", groupRemoveMembersResponse.getFailed())); } } catch (FreeIpaClientException e) { LOGGER.error("Failed to remove {} from group '{}'", users, group, e); warnings.accept(group, String.format("Failed to remove users %s from group: %s", users, e.getMessage())); checkIfClientStillUsable(e); } } } }  Operation synchronizeUsers(String accountId, String actorCrn, Set<String> environmentCrnFilter,
            Set<String> userCrnFilter, Set<String> machineUserCrnFilter); Operation synchronizeUsersWithCustomPermissionCheck(String accountId, String actorCrn, Set<String> environmentCrnFilter,
            UserSyncRequestFilter userSyncFilter, AuthorizationResourceAction action);  }### Answer:
@Test void testRemoveUsersFromGroupsPartitionsRequests() throws Exception { Multimap<String, String> groupMapping = setupGroupMapping(5, underTest.maxSubjectsPerRequest * 2); FreeIpaClient freeIpaClient = mock(FreeIpaClient.class); Group removeResponseGroup = mock(Group.class, RETURNS_DEEP_STUBS); RPCResponse<Group> mockRemoveResponse = mock(RPCResponse.class); when(mockRemoveResponse.getResult()).thenReturn(removeResponseGroup); when(removeResponseGroup.getMemberUser()).thenReturn(List.of()); when(freeIpaClient.groupRemoveMembers(any(), any())).thenReturn(mockRemoveResponse); Multimap<String, String> warnings = ArrayListMultimap.create(); underTest.removeUsersFromGroups(freeIpaClient, groupMapping, warnings::put); groupMapping.keySet().stream().forEach(group -> { try { verify(freeIpaClient, times(2)).groupRemoveMembers(eq(group), any()); } catch (FreeIpaClientException e) { throw new RuntimeException(e); } }); assertTrue(warnings.isEmpty()); }
@Test void testRemoveUsersFromGroupsNullMembersInResponse() throws Exception { Multimap<String, String> groupMapping = setupGroupMapping(1, 1); FreeIpaClient freeIpaClient = mock(FreeIpaClient.class); Group removeResponseGroup = mock(Group.class, RETURNS_DEEP_STUBS); RPCResponse<Group> mockRemoveResponse = mock(RPCResponse.class); when(mockRemoveResponse.getResult()).thenReturn(removeResponseGroup); when(removeResponseGroup.getMemberUser()).thenReturn(null); when(freeIpaClient.groupRemoveMembers(any(), any())).thenReturn(mockRemoveResponse); Multimap<String, String> warnings = ArrayListMultimap.create(); underTest.removeUsersFromGroups(freeIpaClient, groupMapping, warnings::put); assertTrue(warnings.isEmpty()); }