ResourceAggregator { public Map<String, Resource> aggregateByType(List<? extends Resource> resources) { checkSupporting(resources); Map<String, Resource> type2Resource = new HashMap<>(); for (Resource resource : resources) { final Resource resource1 = type2Resource.get(resource.getType()); if (resource1 != null) { type2Resource.put(resource.getType(), aggregate(resource1, resource)); } else { type2Resource.put(resource.getType(), resource); } } return type2Resource; } @Inject  ResourceAggregator(Set<ResourceType> resourcesTypes); Map<String, Resource> aggregateByType(List<? extends Resource> resources); List<? extends Resource> deduct(
      List<? extends Resource> sourceResources, List<? extends Resource> resourcesToDeduct); List<? extends Resource> excess(
      List<? extends Resource> sourceResources, List<? extends Resource> resourcesToCompare); Resource aggregate(Resource resourceA, Resource resourceB); Resource deduct(Resource totalResource, Resource deduction); List<? extends Resource> intersection(
      List<? extends Resource> resourcesA, List<? extends Resource> resourcesB); List<? extends Resource> min(Collection<? extends Resource> resources);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void shouldThrowIllegalArgumentExceptionWhenTryingToAggregateNotSupportedResource() throws Exception { final ResourceImpl dResource = mock(ResourceImpl.class); when(dResource.getType()).thenReturn("resourceD"); resourceAggregator.aggregateByType(singletonList(dResource)); }
@Test(expectedExceptions = IllegalArgumentException.class) public void shouldThrowIllegalArgumentExceptionWhenTryingToAggregateNotSupportedResources() throws Exception { final ResourceImpl dResource = mock(ResourceImpl.class); final ResourceImpl anotherDResource = mock(ResourceImpl.class); when(dResource.getType()).thenReturn("resourceD"); when(anotherDResource.getType()).thenReturn("resourceD"); resourceAggregator.aggregateByType(asList(dResource, anotherDResource)); }