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 4cb23d938..726dafd82 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
@@ -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}.
+ *
+ * It only contains satisfied resource allocations
* @author Óscar González Fernández
*/
public class AggregateOfResourceAllocations {
@@ -45,7 +47,7 @@ public class AggregateOfResourceAllocations {
Validate.notNull(allocations);
Validate.noNullElements(allocations);
this.resourceAllocations = new HashSet>(
- 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> getAllocationsSortedByStartDate() {
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 389e0f4a0..3343f0497 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
@@ -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> allocationsList = Collections
+ .> 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> list = new ArrayList>();
@@ -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);
}