### Question:
UsersStateDifference { public static ImmutableMultimap<String, String> calculateGroupMembershipToRemove(UmsUsersState umsState, UsersState ipaState) { Multimap<String, String> groupMembershipToRemove = HashMultimap.create(); ipaState.getGroupMembership().forEach((group, user) -> { if (!FreeIpaChecks.IPA_UNMANAGED_GROUPS.contains(group) && !umsState.getUsersState().getGroupMembership().containsEntry(group, user)) { LOGGER.debug("removing user : {} to group : {}", user, group); groupMembershipToRemove.put(group, user); } }); LOGGER.info("groupMembershipToRemove size = {}", groupMembershipToRemove.size()); LOGGER.debug("groupMembershipToRemove = {}", groupMembershipToRemove.asMap()); return ImmutableMultimap.copyOf(groupMembershipToRemove); } UsersStateDifference(ImmutableSet<FmsGroup> groupsToAdd, ImmutableSet<FmsGroup> groupsToRemove,
            ImmutableSet<FmsUser> usersToAdd, ImmutableSet<String> usersToRemove,
            ImmutableMultimap<String, String> groupMembershipToAdd, ImmutableMultimap<String, String> groupMembershipToRemove); ImmutableSet<FmsGroup> getGroupsToAdd(); ImmutableSet<FmsGroup> getGroupsToRemove(); ImmutableSet<FmsUser> getUsersToAdd(); ImmutableSet<String> getUsersToRemove(); ImmutableMultimap<String, String> getGroupMembershipToAdd(); ImmutableMultimap<String, String> getGroupMembershipToRemove(); @Override String toString(); static UsersStateDifference fromUmsAndIpaUsersStates(UmsUsersState umsState, UsersState ipaState); static UsersStateDifference forDeletedUser(String deletedUser, Collection<String> groupsToRemove); static ImmutableSet<FmsUser> calculateUsersToAdd(UmsUsersState umsState, UsersState ipaState); static ImmutableSet<String> calculateUsersToRemove(UmsUsersState umsState, UsersState ipaState); static ImmutableSet<FmsGroup> calculateGroupsToAdd(UmsUsersState umsState, UsersState ipaState); static ImmutableSet<FmsGroup> calculateGroupsToRemove(UmsUsersState umsState, UsersState ipaState); static ImmutableMultimap<String, String> calculateGroupMembershipToAdd(UmsUsersState umsState, UsersState ipaState); static ImmutableMultimap<String, String> calculateGroupMembershipToRemove(UmsUsersState umsState, UsersState ipaState);  }### Answer:
@Test void testCalculateGroupMembershipsToRemove() { String group = "group"; String unmanagedGroup = FreeIpaChecks.IPA_UNMANAGED_GROUPS.get(0); String userUms = "userUms"; String userBoth = "userBoth"; String userIPA = "userIPA"; UmsUsersState umsUsersState = new UmsUsersState.Builder() .setUsersState(new UsersState.Builder() .addMemberToGroup(group, userUms) .addMemberToGroup(group, userBoth) .build()) .build(); UsersState ipaUsersState = new UsersState.Builder() .addMemberToGroup(group, userBoth) .addMemberToGroup(group, userIPA) .addMemberToGroup(unmanagedGroup, userUms) .build(); ImmutableMultimap<String, String> groupMembershipsToRemove = UsersStateDifference.calculateGroupMembershipToRemove(umsUsersState, ipaUsersState); assertTrue(groupMembershipsToRemove.get(group).contains(userIPA)); assertFalse(groupMembershipsToRemove.get(unmanagedGroup).contains(userUms)); assertFalse(groupMembershipsToRemove.get(group).contains(userBoth)); assertFalse(groupMembershipsToRemove.get(group).contains(userUms)); }