### Question:
ProvisioningService extends AbstractIdleService { @VisibleForTesting Map<String, Set<String>> groupByRequirement(Set<PluginRequirement> requirements) { Map<String, Set<String>> pluginsGroupedByRequirements = new HashMap<>(); for (PluginRequirement pluginRequirement : requirements) { Set<String> reqs = pluginRequirement.getRequirements().getDatasetTypes(); for (String req : reqs) { Set<String> currentRequirementPlugins = pluginsGroupedByRequirements.getOrDefault(req, new HashSet<>()); currentRequirementPlugins.add(pluginRequirement.getType() + ":" + pluginRequirement.getName()); pluginsGroupedByRequirements.put(req, currentRequirementPlugins); } } return pluginsGroupedByRequirements; } @Inject  ProvisioningService(CConfiguration cConf, ProvisionerProvider provisionerProvider,
                      ProvisionerConfigProvider provisionerConfigProvider,
                      ProvisionerNotifier provisionerNotifier, LocationFactory locationFactory,
                      SecureStore secureStore, ProgramStateWriter programStateWriter,
                      ProvisionerStore provisionerStore, TransactionRunner transactionRunner,
                      MetricsCollectionService metricsCollectionService); ClusterStatus getClusterStatus(ProgramRunId programRunId, ProgramOptions programOptions,
                                        Cluster cluster, String userId); Optional<ProvisioningTaskInfo> cancelProvisionTask(ProgramRunId programRunId); Runnable provision(ProvisionRequest provisionRequest, StructuredTableContext context); Optional<RuntimeJobManager> getRuntimeJobManager(ProgramRunId programRunId, ProgramOptions programOptions); Runnable deprovision(ProgramRunId programRunId, StructuredTableContext context); Collection<ProvisionerDetail> getProvisionerDetails(); @Nullable ProvisionerDetail getProvisionerDetail(String name); void validateProperties(String provisionerName, Map<String, String> properties);  }### Answer:
@Test public void testGroupByRequirement() { Set<PluginRequirement> requirements = ImmutableSet.of(new PluginRequirement("source1", "batchsource", new Requirements(ImmutableSet.of(Table.TYPE, "unicorn"))), new PluginRequirement("sink1", "batchsink", new Requirements(ImmutableSet.of(Table.TYPE, "dragon"))), new PluginRequirement("sink1", "anothersink", new Requirements(ImmutableSet.of(Table.TYPE, "narwhal")))); Map<String, Set<String>> pluginGroupedByRequirement = provisioningService.groupByRequirement(requirements); Assert.assertEquals(4, pluginGroupedByRequirement.size()); Assert.assertEquals(ImmutableSet.of("batchsource:source1", "batchsink:sink1", "anothersink:sink1"), pluginGroupedByRequirement.get(Table.TYPE)); Assert.assertEquals(ImmutableSet.of("batchsource:source1"), pluginGroupedByRequirement.get("unicorn")); Assert.assertEquals(ImmutableSet.of("batchsink:sink1"), pluginGroupedByRequirement.get("dragon")); Assert.assertEquals(ImmutableSet.of("anothersink:sink1"), pluginGroupedByRequirement.get("narwhal")); pluginGroupedByRequirement = provisioningService.groupByRequirement(Collections.emptySet()); Assert.assertTrue(pluginGroupedByRequirement.isEmpty()); }