ItEr27S06CUAsignacionGrupoRecursosAPlanificacionItEr26S07: AggregateOfResourceAllocations can retrieve the resources per day for each allocation

This commit is contained in:
Óscar González Fernández 2009-09-22 19:44:57 +02:00
parent dcd935674b
commit 58e86c4680
2 changed files with 40 additions and 0 deletions

View file

@ -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<ResourceAllocation<?>, ResourcesPerDay> getResourcesPerDay() {
HashMap<ResourceAllocation<?>, ResourcesPerDay> result = new HashMap<ResourceAllocation<?>, ResourcesPerDay>();
for (ResourceAllocation<?> r : resourceAllocations) {
result.put(r, r.getResourcesPerDay());
}
return result;
}
}

View file

@ -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<ResourceAllocation<?>, 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<ResourceAllocation<?>> list = new ArrayList<ResourceAllocation<?>>();
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<ResourceAllocation<?>> list = new ArrayList<ResourceAllocation<?>>();