When setting zero hours on interval the assignments are removed

This commit is contained in:
Óscar González Fernández 2009-10-12 15:46:21 +02:00
parent 92068d72dc
commit d9c7c68a60
2 changed files with 20 additions and 6 deletions

View file

@ -328,12 +328,14 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
Validate.isTrue(startInclusive.compareTo(endExclusive) <= 0,
"the end must be equal or posterior than start");
List<T> assignmentsCreated = new ArrayList<T>();
List<LocalDate> days = getDays(startInclusive, endExclusive);
int[] hoursEachDay = hoursDistribution(days, hours);
int i = 0;
for (LocalDate day : getDays(startInclusive, endExclusive)) {
assignmentsCreated.addAll(distributeForDay(day,
hoursEachDay[i++]));
if (hours > 0) {
List<LocalDate> days = getDays(startInclusive, endExclusive);
int[] hoursEachDay = hoursDistribution(days, hours);
int i = 0;
for (LocalDate day : getDays(startInclusive, endExclusive)) {
assignmentsCreated.addAll(distributeForDay(day,
hoursEachDay[i++]));
}
}
removingAssignments(getAssignments(startInclusive, endExclusive));
addingAssignments(assignmentsCreated);

View file

@ -220,6 +220,18 @@ public class SpecificResourceAllocationTest {
3, 3));
}
@Test
public void allocatingZeroHoursOnIntervalRemovesThem() {
givenResourceCalendarAlwaysReturning(3);
LocalDate start = new LocalDate(2000, 2, 4);
givenSpecificResourceAllocation(start, 4);
specificResourceAllocation.allocate(ResourcesPerDay.amount(1));
specificResourceAllocation.onInterval(start, start.plusDays(2))
.allocateHours(0);
assertThat(specificResourceAllocation.getAssignments(), from(start
.plusDays(2)));
}
@Test
public void theResourcesPerDayAreRecalculatedWhenAllocationHoursOnInterval() {
givenResourceCalendarAlwaysReturning(3);