ItEr46S12CUVisualizacionResponsabilidadesTRaballoNaPlanificacion: AggregateOfResourceAllocations only contains satisfied allocations

This commit is contained in:
Óscar González Fernández 2010-02-03 20:27:09 +01:00
parent 5349103671
commit 16b7bce31a
2 changed files with 25 additions and 12 deletions

View file

@ -33,7 +33,9 @@ import org.joda.time.Days;
import org.joda.time.LocalDate;
/**
* Computes aggregate values on a set{@link ResourceAllocation}
* Computes aggregate values on a set{@link ResourceAllocation}.
* <p>
* It only contains satisfied resource allocations
* @author Óscar González Fernández <ogonzalez@igalia.com>
*/
public class AggregateOfResourceAllocations {
@ -45,7 +47,7 @@ public class AggregateOfResourceAllocations {
Validate.notNull(allocations);
Validate.noNullElements(allocations);
this.resourceAllocations = new HashSet<ResourceAllocation<?>>(
allocations);
ResourceAllocation.getSatisfied(allocations));
}
public int getTotalHours() {
@ -65,16 +67,7 @@ public class AggregateOfResourceAllocations {
}
public boolean isEmpty() {
return resourceAllocations.isEmpty() || allEmpty();
}
private boolean allEmpty() {
for (ResourceAllocation<?> each : resourceAllocations) {
if (each.hasAssignments()) {
return false;
}
}
return true;
return resourceAllocations.isEmpty();
}
public List<ResourceAllocation<?>> getAllocationsSortedByStartDate() {

View file

@ -30,6 +30,7 @@ import static org.junit.matchers.JUnitMatchers.hasItem;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@ -66,6 +67,15 @@ public class AggregateOfResourceAllocationsTest {
assertTrue(aggregate.isEmpty());
}
@Test
public void unsatisfiedAllocationsAreIgnored() {
List<ResourceAllocation<?>> allocationsList = Collections
.<ResourceAllocation<?>> singletonList(givenUnsatisfiedResourceAllocation());
AggregateOfResourceAllocations aggregate = new AggregateOfResourceAllocations(
allocationsList);
assertTrue(aggregate.isEmpty());
}
@Test
public void calculatesTheTotalHours() {
givenAggregateOfResourceAllocationsWithAssignedHours(4, 5, 6);
@ -92,12 +102,20 @@ public class AggregateOfResourceAllocationsTest {
ResourceAllocation<?> resourceAllocation = createMock(ResourceAllocation.class);
expect(resourceAllocation.getResourcesPerDay()).andReturn(r)
.anyTimes();
expect(resourceAllocation.isSatisfied()).andReturn(true).anyTimes();
replay(resourceAllocation);
list.add(resourceAllocation);
}
aggregate = new AggregateOfResourceAllocations(list);
}
private ResourceAllocation<?> givenUnsatisfiedResourceAllocation() {
ResourceAllocation<?> result = createMock(ResourceAllocation.class);
expect(result.isSatisfied()).andReturn(false).anyTimes();
replay(result);
return result;
}
private void givenAggregateOfResourceAllocationsWithAssignedHours(
int... hours) {
ArrayList<ResourceAllocation<?>> list = new ArrayList<ResourceAllocation<?>>();
@ -105,6 +123,8 @@ public class AggregateOfResourceAllocationsTest {
ResourceAllocation<?> resourceAllocation = createMock(ResourceAllocation.class);
expect(resourceAllocation.getAssignedHours()).andReturn(h)
.anyTimes();
expect(resourceAllocation.isSatisfied()).andReturn(true)
.anyTimes();
replay(resourceAllocation);
list.add(resourceAllocation);
}