### Question:
UsersStateDifference { public static ImmutableSet<FmsGroup> calculateGroupsToAdd(UmsUsersState umsState, UsersState ipaState) { ImmutableSet<FmsGroup> groupsToAdd = ImmutableSet.copyOf(Sets.difference(umsState.getUsersState().getGroups(), ipaState.getGroups()) .stream() .filter(fmsGroup -> !FreeIpaChecks.IPA_PROTECTED_GROUPS.contains(fmsGroup.getName())) .collect(Collectors.toSet())); LOGGER.info("groupsToAdd size = {}", groupsToAdd.size()); LOGGER.debug("groupsToAdd = {}", groupsToAdd.stream().map(FmsGroup::getName).collect(Collectors.toSet())); return groupsToAdd; } 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 testCalculateGroupsToAdd() { FmsGroup groupUms = new FmsGroup().withName("groupUms"); FmsGroup groupWag = new FmsGroup().withName("groupWag"); FmsGroup groupBoth = new FmsGroup().withName("groupBoth"); FmsGroup groupIPA = new FmsGroup().withName("groupIPA"); FmsGroup groupProtected = new FmsGroup().withName(FreeIpaChecks.IPA_PROTECTED_GROUPS.get(0)); UmsUsersState umsUsersState = new UmsUsersState.Builder() .setUsersState(new UsersState.Builder() .addGroup(groupUms) .addGroup(groupBoth) .addGroup(groupProtected) .build()) .setWorkloadAdministrationGroups(Set.of(groupWag)) .build(); UsersState ipaUsersState = new UsersState.Builder() .addGroup(groupBoth) .addGroup(groupIPA) .build(); ImmutableSet<FmsGroup> groupsToAdd = UsersStateDifference.calculateGroupsToAdd(umsUsersState, ipaUsersState); assertTrue(groupsToAdd.contains(groupUms)); assertFalse(groupsToAdd.contains(groupProtected)); assertFalse(groupsToAdd.contains(groupWag)); assertFalse(groupsToAdd.contains(groupBoth)); assertFalse(groupsToAdd.contains(groupIPA)); }