### Question:
ClouderaManagerParcelService { public void deactivateUnusedParcels(ParcelsResourceApi parcelsResourceApi, ParcelResourceApi parcelResourceApi, String stackName, Map<String, ClouderaManagerProduct> cmProducts) { Map<String, String> installedComponents = getParcelsInStatus(parcelsResourceApi, stackName, ParcelStatus.ACTIVATED); Map<String, String> filteredParcels = installedComponents.entrySet().stream() .filter(entry -> !cmProducts.containsKey(entry.getKey())) .collect(toMap(Map.Entry::getKey, Map.Entry::getValue)); deactivateParcels(parcelResourceApi, stackName, filteredParcels); }  Map<String, String> getParcelsInStatus(ParcelsResourceApi parcelsResourceApi, String stackName, ParcelStatus parcelStatus); void deactivateUnusedParcels(ParcelsResourceApi parcelsResourceApi, ParcelResourceApi parcelResourceApi, String stackName, Map<String,
            ClouderaManagerProduct> cmProducts); void undistributeUnusedParcels(ApiClient apiClient, ParcelsResourceApi parcelsResourceApi, ParcelResourceApi parcelResourceApi, Stack stack,
            Map<String, ClouderaManagerProduct> cmProducts); void removeUnusedParcels(ApiClient apiClient, ParcelsResourceApi parcelsResourceApi, ParcelResourceApi parcelResourceApi, Stack stack,
            Map<String, ClouderaManagerProduct> cmProducts); void removeUnusedParcelVersions(ApiClient apiClient, ParcelsResourceApi parcelsResourceApi, ParcelResourceApi parcelResourceApi, Stack stack,
            String parcel, String usedVersion);  }### Answer:
@Test public void testDeactivateUnusedComponents() throws Exception { Map<String, ClouderaManagerProduct> usedComponents = new HashMap<>(); usedComponents.put("product1", createClouderaManagerProduct("product1", "version1")); usedComponents.put("prodcut2", createClouderaManagerProduct("product2", "version2")); Map<String, String> activatedParcels = Map.of("product1", "version1", "product3", "version3"); ApiParcelList parcelList = createApiParcelList(activatedParcels, ParcelStatus.ACTIVATED); when(parcelsResourceApi.readParcels("stackname", "summary")).thenReturn(parcelList); underTest.deactivateUnusedParcels(parcelsResourceApi, parcelResourceApi, "stackname", usedComponents); verify(parcelResourceApi, times(1)).deactivateCommand("stackname", "product3", "version3"); verify(parcelResourceApi, times(0)).deactivateCommand("stackname", "product1", "version1"); verify(parcelResourceApi, times(0)).deactivateCommand("stackname", "product2", "version2"); }
@Test public void testDeactivateUnusedComponentsWhenDeactivateThrowException() throws Exception { Map<String, ClouderaManagerProduct> usedComponents = new HashMap<>(); usedComponents.put("product1", createClouderaManagerProduct("product1", "version1")); usedComponents.put("prodcut2", createClouderaManagerProduct("product2", "version2")); Map<String, String> activatedParcels = Map.of("product1", "version1", "product3", "version3"); ApiParcelList parcelList = createApiParcelList(activatedParcels, ParcelStatus.ACTIVATED); when(parcelsResourceApi.readParcels("stackname", "summary")).thenReturn(parcelList); when(parcelResourceApi.deactivateCommand("stackname", "product3", "version3")).thenThrow(new ApiException()); Assertions.assertThrows(ClouderaManagerOperationFailedException.class, () -> underTest.deactivateUnusedParcels(parcelsResourceApi, parcelResourceApi, "stackname", usedComponents)); }