### Question:
PermissionManager { public List<Group> getAllGroupsWithoutExcluded(List<Group> excludedGroupsList, JtalksPermission permission) { List<Group> allGroups = groupDao.getAll(); allGroups.removeAll(excludedGroupsList); if (permission.equals(BranchPermission.VIEW_TOPICS) && !excludedGroupsList.contains(AnonymousGroup.ANONYMOUS_GROUP)) { allGroups.add(AnonymousGroup.ANONYMOUS_GROUP); } return allGroups; } PermissionManager(@Nonnull AclManager aclManager, @Nonnull GroupDao groupDao,
                             @Nonnull AclUtil aclUtil, @Nonnull PluginPermissionManager pluginPermissionManager); void changeGrants(Entity entity, PermissionChanges changes); void changeRestrictions(Entity entity, PermissionChanges changes); GroupsPermissions getPermissionsMapFor(Branch branch); JtalksPermission findBranchPermissionByMask(int mask); GroupsPermissions getPermissionsMapFor(Component component); GroupsPermissions getPermissionsMapFor(List<Group> groups); GroupsPermissions getPermissionsMapFor(List<JtalksPermission> permissions, Entity entity); List<Group> getAllGroupsWithoutExcluded(List<Group> excludedGroupsList, JtalksPermission permission); List<Group> getGroupsByIds(List<Long> groupIds);  }### Answer:
@Test public void getAllGroupsWithoutExcludedShouldReturnAllGroupsWhenExcludedListIsEmpty() { List<Group> allGroups = Arrays.asList(new Group("1"), new Group("2")); when(groupDao.getAll()).thenReturn(allGroups); List<Group> result = manager.getAllGroupsWithoutExcluded(Collections.EMPTY_LIST, BranchPermission.CLOSE_TOPICS); assertEquals(allGroups, result); }
@Test public void getAllGroupsWithoutExcludedShouldReturnAllGroupsWithoutExcluded() { Group excludedGroup = new Group("1"); List<Group> allGroups = new ArrayList<>(Arrays.asList(excludedGroup, new Group("2"))); when(groupDao.getAll()).thenReturn(allGroups); List<Group> result = manager.getAllGroupsWithoutExcluded(Arrays.asList(excludedGroup), BranchPermission.CLOSE_TOPICS); assertEquals(result.size(), 1); assertEquals(result.get(0), allGroups.get(0)); }
@Test public void getAllGroupsWithoutExcludedShouldReturnListWithAnonymousGroupWhenItNotExcludedAndRequestedViewTopicPermission() { Group excludedGroup = new Group("1"); List<Group> allGroups = new ArrayList<>(Arrays.asList(excludedGroup, new Group("2"))); when(groupDao.getAll()).thenReturn(allGroups); List<Group> result = manager.getAllGroupsWithoutExcluded(Arrays.asList(excludedGroup), BranchPermission.VIEW_TOPICS); assertTrue(result.contains(AnonymousGroup.ANONYMOUS_GROUP)); }