### Question:
FileResourceGroupConfigurationManager extends AbstractResourceConfigurationManager { @Override public Optional<SelectionContext<ResourceGroupIdTemplate>> match(SelectionCriteria criteria) { return selectors.stream() .map(s -> s.match(criteria)) .filter(Optional::isPresent) .map(Optional::get) .findFirst(); } @Inject  FileResourceGroupConfigurationManager(ClusterMemoryPoolManager memoryPoolManager, FileResourceGroupConfig config); @VisibleForTesting  FileResourceGroupConfigurationManager(ClusterMemoryPoolManager memoryPoolManager, ManagerSpec managerSpec); @Override void configure(ResourceGroup group, SelectionContext<ResourceGroupIdTemplate> context); @Override Optional<SelectionContext<ResourceGroupIdTemplate>> match(SelectionCriteria criteria);  }### Answer:
@Test public void testMatchByUserGroups() { ManagerSpec managerSpec = managerSpec( resourceGroupSpec("group"), ImmutableList.of(selectorSpec(groupIdTemplate("group")) .userGroups("first matching", "second matching"))); FileResourceGroupConfigurationManager groupManager = new FileResourceGroupConfigurationManager((poolId, listener) -> {}, managerSpec); assertThat(groupManager.match(userGroupsSelectionCriteria("not matching"))).isEmpty(); assertThat(groupManager.match(userGroupsSelectionCriteria("first matching"))) .map(SelectionContext::getContext) .isEqualTo(Optional.of(groupIdTemplate("group"))); }
@Test public void testMatchByUsers() { ManagerSpec managerSpec = managerSpec( resourceGroupSpec("group"), ImmutableList.of(selectorSpec(groupIdTemplate("group")) .users("First matching user", "Second matching user"))); FileResourceGroupConfigurationManager groupManager = new FileResourceGroupConfigurationManager((poolId, listener) -> {}, managerSpec); assertThat(groupManager.match(userSelectionCriteria("Not matching user"))).isEmpty(); assertThat(groupManager.match(userSelectionCriteria("First matching user"))) .map(SelectionContext::getContext) .isEqualTo(Optional.of(groupIdTemplate("group"))); }
@Test public void testMatchByUsersAndGroups() { ManagerSpec managerSpec = managerSpec( resourceGroupSpec("group"), ImmutableList.of(selectorSpec(groupIdTemplate("group")) .userGroups("Matching group") .users("Matching user"))); FileResourceGroupConfigurationManager groupManager = new FileResourceGroupConfigurationManager((poolId, listener) -> {}, managerSpec); assertThat(groupManager.match(userAndUserGroupsSelectionCriteria("Matching user", "Not matching group"))).isEmpty(); assertThat(groupManager.match(userAndUserGroupsSelectionCriteria("Not matching user", "Matching group"))).isEmpty(); assertThat(groupManager.match(userAndUserGroupsSelectionCriteria("Matching user", "Matching group"))) .map(SelectionContext::getContext) .isEqualTo(Optional.of(groupIdTemplate("group"))); }