diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/AggregateOfResourceAllocations.java b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/AggregateOfResourceAllocations.java index eafe23ccd..edbc29fc9 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/AggregateOfResourceAllocations.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/planner/entities/AggregateOfResourceAllocations.java @@ -1,7 +1,9 @@ package org.navalplanner.business.planner.entities; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; import org.apache.commons.lang.Validate; @@ -30,4 +32,12 @@ public class AggregateOfResourceAllocations { return sum; } + public Map, ResourcesPerDay> getResourcesPerDay() { + HashMap, ResourcesPerDay> result = new HashMap, ResourcesPerDay>(); + for (ResourceAllocation r : resourceAllocations) { + result.put(r, r.getResourcesPerDay()); + } + return result; + } + } diff --git a/navalplanner-business/src/test/java/org/navalplanner/business/test/planner/entities/AggregateOfResourceAllocationsTest.java b/navalplanner-business/src/test/java/org/navalplanner/business/test/planner/entities/AggregateOfResourceAllocationsTest.java index 282dcf611..41e35794e 100644 --- a/navalplanner-business/src/test/java/org/navalplanner/business/test/planner/entities/AggregateOfResourceAllocationsTest.java +++ b/navalplanner-business/src/test/java/org/navalplanner/business/test/planner/entities/AggregateOfResourceAllocationsTest.java @@ -5,13 +5,17 @@ import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.classextension.EasyMock.replay; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; +import static org.junit.matchers.JUnitMatchers.hasItem; import java.util.ArrayList; +import java.util.Collection; import java.util.List; +import java.util.Map; import org.junit.Test; import org.navalplanner.business.planner.entities.AggregateOfResourceAllocations; import org.navalplanner.business.planner.entities.ResourceAllocation; +import org.navalplanner.business.planner.entities.ResourcesPerDay; public class AggregateOfResourceAllocationsTest { @@ -41,6 +45,32 @@ public class AggregateOfResourceAllocationsTest { assertThat(aggregate.getTotalHours(), equalTo(15)); } + @Test + public void canCalculateTheResourcesPerDay() { + givenAggregateOfResourceAllocationsWithResourcesPerDay(ResourcesPerDay + .amount(2), ResourcesPerDay.amount(3)); + Map, ResourcesPerDay> resourcesPerDay = aggregate + .getResourcesPerDay(); + assertThat(resourcesPerDay.size(), equalTo(2)); + assertThat(resourcesPerDay.values(), hasItem(equalTo(ResourcesPerDay + .amount(2)))); + assertThat(resourcesPerDay.values(), hasItem(equalTo(ResourcesPerDay + .amount(3)))); + } + + private void givenAggregateOfResourceAllocationsWithResourcesPerDay( + ResourcesPerDay... resourcesPerDay) { + Collection> list = new ArrayList>(); + for (ResourcesPerDay r : resourcesPerDay) { + ResourceAllocation resourceAllocation = createMock(ResourceAllocation.class); + expect(resourceAllocation.getResourcesPerDay()).andReturn(r) + .anyTimes(); + replay(resourceAllocation); + list.add(resourceAllocation); + } + aggregate = new AggregateOfResourceAllocations(list); + } + private void givenAggregateOfResourceAllocationsWithAssignedHours( int... hours) { ArrayList> list = new ArrayList>();