ItEr41S09RFSoporteRecursosVirtuaisItEr40S12: Using toHours method
This commit is contained in:
parent
600c87936a
commit
d53a64f2bc
2 changed files with 38 additions and 19 deletions
|
|
@ -450,8 +450,7 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
|
|||
|
||||
final int calculateTotalToDistribute(LocalDate day,
|
||||
ResourcesPerDay resourcesPerDay) {
|
||||
Integer workableHours = getWorkHoursPerDay().getCapacityAt(day);
|
||||
return resourcesPerDay.asHoursGivenResourceWorkingDayOf(workableHours);
|
||||
return getWorkHoursPerDay().toHours(day, resourcesPerDay);
|
||||
}
|
||||
|
||||
private ResourcesPerDay calculateResourcesPerDayFromAssignments() {
|
||||
|
|
@ -459,16 +458,16 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
|
|||
.byDay(getAssignments());
|
||||
int sumTotalHours = 0;
|
||||
int sumWorkableHours = 0;
|
||||
final ResourcesPerDay one = ResourcesPerDay.amount(1);
|
||||
for (Entry<LocalDate, List<DayAssignment>> entry : byDay.entrySet()) {
|
||||
sumWorkableHours += getWorkHoursPerDay().getCapacityAt(
|
||||
entry.getKey());
|
||||
sumWorkableHours += getWorkHoursPerDay().toHours(entry.getKey(),
|
||||
one);
|
||||
sumTotalHours += getAssignedHours(entry.getValue());
|
||||
}
|
||||
if (sumWorkableHours == 0) {
|
||||
return ResourcesPerDay.amount(0);
|
||||
}
|
||||
return ResourcesPerDay.calculateFrom(
|
||||
sumTotalHours, sumWorkableHours);
|
||||
return ResourcesPerDay.calculateFrom(sumTotalHours, sumWorkableHours);
|
||||
}
|
||||
|
||||
private IWorkHours getWorkHoursPerDay() {
|
||||
|
|
|
|||
|
|
@ -65,15 +65,30 @@ public class SpecificResourceAllocationTest {
|
|||
this.assignedHours = assignedHours;
|
||||
}
|
||||
|
||||
private void givenResourceCalendarAlwaysReturning(int hours) {
|
||||
private void givenResourceCalendarAlwaysReturning(final int hours) {
|
||||
this.calendar = createNiceMock(ResourceCalendar.class);
|
||||
expect(this.calendar.getCapacityAt(isA(LocalDate.class))).andReturn(
|
||||
hours).anyTimes();
|
||||
expect(this.calendar.getWorkableHours(isA(Date.class)))
|
||||
.andReturn(hours).anyTimes();
|
||||
expect(this.calendar.toHours(isA(LocalDate.class),
|
||||
isA(ResourcesPerDay.class))).andAnswer(
|
||||
toHoursAnswer(hours)).anyTimes();
|
||||
replay(this.calendar);
|
||||
}
|
||||
|
||||
private IAnswer<Integer> toHoursAnswer(final int hours) {
|
||||
return new IAnswer<Integer>() {
|
||||
|
||||
@Override
|
||||
public Integer answer() throws Throwable {
|
||||
ResourcesPerDay perDay = (ResourcesPerDay) EasyMock
|
||||
.getCurrentArguments()[1];
|
||||
return perDay.asHoursGivenResourceWorkingDayOf(hours);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void givenResourceCalendar(final int defaultAnswer, final Map<LocalDate, Integer> answersForDates){
|
||||
this.calendar = createNiceMock(ResourceCalendar.class);
|
||||
expect(this.calendar.getCapacityAt(isA(LocalDate.class))).andAnswer(new IAnswer<Integer>() {
|
||||
|
|
@ -87,19 +102,24 @@ public class SpecificResourceAllocationTest {
|
|||
return defaultAnswer;
|
||||
}
|
||||
}).anyTimes();
|
||||
expect(this.calendar.getWorkableHours(isA(Date.class)))
|
||||
.andAnswer(new IAnswer<Integer>() {
|
||||
expect(
|
||||
this.calendar.toHours(isA(LocalDate.class),
|
||||
isA(ResourcesPerDay.class))).andAnswer(
|
||||
new IAnswer<Integer>() {
|
||||
|
||||
@Override
|
||||
public Integer answer() throws Throwable {
|
||||
Date date = (Date) EasyMock.getCurrentArguments()[0];
|
||||
LocalDate localDate = new LocalDate(date.getTime());
|
||||
if(answersForDates.containsKey(localDate)){
|
||||
return answersForDates.get(localDate);
|
||||
}
|
||||
return defaultAnswer;
|
||||
}
|
||||
}).anyTimes();
|
||||
@Override
|
||||
public Integer answer() throws Throwable {
|
||||
LocalDate date = (LocalDate) EasyMock
|
||||
.getCurrentArguments()[0];
|
||||
int hours;
|
||||
if (answersForDates.containsKey(date)) {
|
||||
hours = answersForDates.get(date);
|
||||
} else {
|
||||
hours = defaultAnswer;
|
||||
}
|
||||
return toHoursAnswer(hours).answer();
|
||||
}
|
||||
}).anyTimes();
|
||||
replay(this.calendar);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue