Add new method for retrieving exact capacity duration.
The old method working with hours is now deprecated so its use is discouraged. Eventually it will be phased out. Change calendar test method to test the new method. FEA: ItEr60S19TimeUnitDataType
This commit is contained in:
parent
9263f1ad21
commit
bef951f827
10 changed files with 170 additions and 81 deletions
|
|
@ -299,8 +299,13 @@ public class BaseCalendar extends IntegrationEntity implements IWorkHours {
|
|||
* Returns the number of workable hours for a specific date depending on the
|
||||
* calendar restrictions.
|
||||
*/
|
||||
@Deprecated
|
||||
public Integer getCapacityAt(LocalDate date) {
|
||||
return roundToHours(getWorkableTimeAt(date));
|
||||
return roundToHours(getCapacityDurationAt(date));
|
||||
}
|
||||
|
||||
public EffortDuration getCapacityDurationAt(LocalDate date) {
|
||||
return getWorkableTimeAt(date);
|
||||
}
|
||||
|
||||
public EffortDuration getWorkableTimeAt(LocalDate date) {
|
||||
|
|
|
|||
|
|
@ -24,10 +24,12 @@ import static java.util.Arrays.asList;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.workingday.EffortDuration;
|
||||
import org.navalplanner.business.workingday.ResourcesPerDay;
|
||||
|
||||
public abstract class CombinedWorkHours implements IWorkHours {
|
||||
|
|
@ -69,10 +71,16 @@ public abstract class CombinedWorkHours implements IWorkHours {
|
|||
|
||||
@Override
|
||||
public Integer getCapacityAt(LocalDate date) {
|
||||
Integer current = null;
|
||||
return BaseCalendar.roundToHours(getCapacityDurationAt(date));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EffortDuration getCapacityDurationAt(LocalDate date) {
|
||||
EffortDuration current = null;
|
||||
for (IWorkHours workHour : workHours) {
|
||||
current = current == null ? workHour.getCapacityAt(date)
|
||||
: updateCapacity(current, workHour.getCapacityAt(date));
|
||||
current = current == null ? workHour.getCapacityDurationAt(date)
|
||||
: updateCapacity(current,
|
||||
workHour.getCapacityDurationAt(date));
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
|
@ -101,7 +109,8 @@ public abstract class CombinedWorkHours implements IWorkHours {
|
|||
|
||||
protected abstract Integer updateHours(Integer current, Integer each);
|
||||
|
||||
protected abstract Integer updateCapacity(Integer current, Integer each);
|
||||
protected abstract EffortDuration updateCapacity(EffortDuration current,
|
||||
EffortDuration each);
|
||||
|
||||
@Override
|
||||
public boolean thereAreHoursOn(AvailabilityTimeLine availability,
|
||||
|
|
@ -118,8 +127,9 @@ class Min extends CombinedWorkHours {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Integer updateCapacity(Integer current, Integer each) {
|
||||
return Math.min(current, each);
|
||||
protected EffortDuration updateCapacity(EffortDuration current,
|
||||
EffortDuration each) {
|
||||
return Collections.min(asList(current, each));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -142,8 +152,9 @@ class Max extends CombinedWorkHours {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Integer updateCapacity(Integer current, Integer each) {
|
||||
return Math.max(current, each);
|
||||
protected EffortDuration updateCapacity(EffortDuration current,
|
||||
EffortDuration each) {
|
||||
return Collections.max(asList(current, each));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
package org.navalplanner.business.calendars.entities;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.workingday.EffortDuration;
|
||||
import org.navalplanner.business.workingday.ResourcesPerDay;
|
||||
|
||||
public interface IWorkHours {
|
||||
|
|
@ -37,11 +38,24 @@ public interface IWorkHours {
|
|||
/**
|
||||
* Calculates the capacity at a given date. It means all the hours that
|
||||
* could be worked without having overtime
|
||||
*
|
||||
* @param date
|
||||
* the date at which the capacity is calculated
|
||||
* @return the capacity at which the resource can work
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
public Integer getCapacityAt(LocalDate date);
|
||||
|
||||
/**
|
||||
* Calculates the capacity duration at a given date. It means all the time
|
||||
* that could be worked without having overtime
|
||||
*
|
||||
* @param date
|
||||
* the date at which the capacity is calculated
|
||||
* @return the capacity at which the resource can work
|
||||
*/
|
||||
public Integer getCapacityAt(LocalDate date);
|
||||
public EffortDuration getCapacityDurationAt(LocalDate date);
|
||||
|
||||
public AvailabilityTimeLine getAvailability();
|
||||
|
||||
|
|
|
|||
|
|
@ -75,11 +75,11 @@ public class ResourceCalendar extends BaseCalendar {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Integer getCapacityAt(LocalDate date) {
|
||||
public EffortDuration getCapacityDurationAt(LocalDate date) {
|
||||
if (!isActive(date)) {
|
||||
return 0;
|
||||
return EffortDuration.zero();
|
||||
}
|
||||
return multiplyByCapacity(super.getCapacityAt(date));
|
||||
return multiplyByCapacity(super.getCapacityDurationAt(date));
|
||||
}
|
||||
|
||||
protected Integer multiplyByCapacity(Integer duration) {
|
||||
|
|
|
|||
|
|
@ -42,10 +42,16 @@ public class SameWorkHoursEveryDay implements IWorkHours {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Integer getCapacityAt(LocalDate date) {
|
||||
return hours;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EffortDuration getCapacityDurationAt(LocalDate date) {
|
||||
return EffortDuration.hours(hours);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer toHours(LocalDate day, ResourcesPerDay amount) {
|
||||
return BaseCalendar.roundToHours(amount
|
||||
|
|
@ -63,4 +69,5 @@ public class SameWorkHoursEveryDay implements IWorkHours {
|
|||
public AvailabilityTimeLine getAvailability() {
|
||||
return AvailabilityTimeLine.allValid();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ import java.util.HashSet;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.hibernate.validator.Min;
|
||||
|
|
@ -60,6 +60,7 @@ import org.navalplanner.business.scenarios.IScenarioManager;
|
|||
import org.navalplanner.business.scenarios.entities.Scenario;
|
||||
import org.navalplanner.business.util.deepcopy.OnCopy;
|
||||
import org.navalplanner.business.util.deepcopy.Strategy;
|
||||
import org.navalplanner.business.workingday.EffortDuration;
|
||||
import org.navalplanner.business.workingday.ResourcesPerDay;
|
||||
|
||||
/**
|
||||
|
|
@ -748,6 +749,11 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
|
|||
return getSubyacent().getCapacityAt(day);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EffortDuration getCapacityDurationAt(LocalDate date) {
|
||||
return getSubyacent().getCapacityDurationAt(date);
|
||||
}
|
||||
|
||||
private IWorkHours getSubyacent() {
|
||||
if (getTaskCalendar() == null) {
|
||||
return SameWorkHoursEveryDay.getDefaultWorkingDay();
|
||||
|
|
|
|||
|
|
@ -145,11 +145,13 @@ public class BaseCalendarTest {
|
|||
public void testGetWorkableHoursBasic() {
|
||||
BaseCalendar calendar = createBasicCalendar();
|
||||
|
||||
int wednesdayHours = calendar.getCapacityAt(WEDNESDAY_LOCAL_DATE);
|
||||
assertThat(wednesdayHours, equalTo(8));
|
||||
EffortDuration wednesdayHours = calendar
|
||||
.getCapacityDurationAt(WEDNESDAY_LOCAL_DATE);
|
||||
assertThat(wednesdayHours, equalTo(hours(8)));
|
||||
|
||||
int sundayHours = calendar.getCapacityAt(SUNDAY_LOCAL_DATE);
|
||||
assertThat(sundayHours, equalTo(0));
|
||||
EffortDuration sundayHours = calendar
|
||||
.getCapacityDurationAt(SUNDAY_LOCAL_DATE);
|
||||
assertThat(sundayHours, equalTo(zero()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -162,8 +164,9 @@ public class BaseCalendarTest {
|
|||
public void testGetWorkableHoursChristmas() {
|
||||
BaseCalendar calendar = createChristmasCalendar();
|
||||
|
||||
int hours = calendar.getCapacityAt(CHRISTMAS_DAY_LOCAL_DATE);
|
||||
assertThat(hours, equalTo(0));
|
||||
EffortDuration duration = calendar
|
||||
.getCapacityDurationAt(CHRISTMAS_DAY_LOCAL_DATE);
|
||||
assertThat(duration, equalTo(EffortDuration.zero()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -178,19 +181,22 @@ public class BaseCalendarTest {
|
|||
public void testGetWorkableHoursDerivedBasicCalendar() {
|
||||
BaseCalendar calendar = createBasicCalendar().newDerivedCalendar();
|
||||
|
||||
int wednesdayHours = calendar.getCapacityAt(WEDNESDAY_LOCAL_DATE);
|
||||
assertThat(wednesdayHours, equalTo(8));
|
||||
EffortDuration wednesdayHours = calendar
|
||||
.getCapacityDurationAt(WEDNESDAY_LOCAL_DATE);
|
||||
assertThat(wednesdayHours, equalTo(hours(8)));
|
||||
|
||||
int sundayHours = calendar.getCapacityAt(SUNDAY_LOCAL_DATE);
|
||||
assertThat(sundayHours, equalTo(0));
|
||||
EffortDuration sundayHours = calendar
|
||||
.getCapacityDurationAt(SUNDAY_LOCAL_DATE);
|
||||
assertThat(sundayHours, equalTo(zero()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetWorkableHoursDerivedChristmasCalendar() {
|
||||
BaseCalendar calendar = createChristmasCalendar().newDerivedCalendar();
|
||||
|
||||
int hours = calendar.getCapacityAt(CHRISTMAS_DAY_LOCAL_DATE);
|
||||
assertThat(hours, equalTo(0));
|
||||
EffortDuration hours = calendar
|
||||
.getCapacityDurationAt(CHRISTMAS_DAY_LOCAL_DATE);
|
||||
assertThat(hours, equalTo(EffortDuration.zero()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -201,14 +207,17 @@ public class BaseCalendarTest {
|
|||
hours(4), createCalendarExceptionType());
|
||||
calendar.addExceptionDay(day);
|
||||
|
||||
int mondayHours = calendar.getCapacityAt(MONDAY_LOCAL_DATE);
|
||||
assertThat(mondayHours, equalTo(8));
|
||||
EffortDuration mondayHours = calendar
|
||||
.getCapacityDurationAt(MONDAY_LOCAL_DATE);
|
||||
assertThat(mondayHours, equalTo(hours(8)));
|
||||
|
||||
int wednesdayHours = calendar.getCapacityAt(WEDNESDAY_LOCAL_DATE);
|
||||
assertThat(wednesdayHours, equalTo(4));
|
||||
EffortDuration wednesdayHours = calendar
|
||||
.getCapacityDurationAt(WEDNESDAY_LOCAL_DATE);
|
||||
assertThat(wednesdayHours, equalTo(hours(4)));
|
||||
|
||||
int sundayHours = calendar.getCapacityAt(SUNDAY_LOCAL_DATE);
|
||||
assertThat(sundayHours, equalTo(0));
|
||||
EffortDuration sundayHours = calendar
|
||||
.getCapacityDurationAt(SUNDAY_LOCAL_DATE);
|
||||
assertThat(sundayHours, equalTo(zero()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -220,8 +229,9 @@ public class BaseCalendarTest {
|
|||
createCalendarExceptionType());
|
||||
calendar.addExceptionDay(day);
|
||||
|
||||
int hours = calendar.getCapacityAt(CHRISTMAS_DAY_LOCAL_DATE);
|
||||
assertThat(hours, equalTo(4));
|
||||
EffortDuration hours = calendar
|
||||
.getCapacityDurationAt(CHRISTMAS_DAY_LOCAL_DATE);
|
||||
assertThat(hours, equalTo(hours(4)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -298,16 +308,18 @@ public class BaseCalendarTest {
|
|||
calendar.setDurationAt(Days.WEDNESDAY, hours(4));
|
||||
calendar.setDurationAt(Days.SUNDAY, hours(4));
|
||||
|
||||
assertThat(calendar.getCapacityAt(WEDNESDAY_LOCAL_DATE), equalTo(4));
|
||||
assertThat(calendar.getCapacityDurationAt(WEDNESDAY_LOCAL_DATE),
|
||||
equalTo(hours(4)));
|
||||
|
||||
assertThat(calendar
|
||||
.getCapacityAt(WEDNESDAY_LOCAL_DATE.minusWeeks(1)),
|
||||
equalTo(8));
|
||||
assertThat(calendar.getCapacityDurationAt(WEDNESDAY_LOCAL_DATE
|
||||
.minusWeeks(1)), equalTo(hours(8)));
|
||||
|
||||
assertThat(calendar.getCapacityAt(SUNDAY_LOCAL_DATE), equalTo(4));
|
||||
assertThat(calendar.getCapacityDurationAt(SUNDAY_LOCAL_DATE),
|
||||
equalTo(hours(4)));
|
||||
|
||||
assertThat(calendar.getCapacityAt(SUNDAY_LOCAL_DATE.minusWeeks(1)),
|
||||
equalTo(0));
|
||||
assertThat(
|
||||
calendar.getCapacityDurationAt(SUNDAY_LOCAL_DATE.minusWeeks(1)),
|
||||
equalTo(zero()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -318,15 +330,19 @@ public class BaseCalendarTest {
|
|||
calendar.setDurationAt(Days.MONDAY, hours(1));
|
||||
calendar.setDurationAt(Days.SUNDAY, hours(2));
|
||||
|
||||
assertThat(calendar.getCapacityAt(MONDAY_LOCAL_DATE), equalTo(1));
|
||||
assertThat(calendar.getCapacityDurationAt(MONDAY_LOCAL_DATE),
|
||||
equalTo(hours(1)));
|
||||
|
||||
assertThat(calendar.getCapacityAt(SUNDAY_LOCAL_DATE), equalTo(2));
|
||||
assertThat(calendar.getCapacityDurationAt(SUNDAY_LOCAL_DATE),
|
||||
equalTo(hours(2)));
|
||||
|
||||
assertThat(calendar
|
||||
.getCapacityAt(MONDAY_LOCAL_DATE.minusWeeks(1)), equalTo(8));
|
||||
assertThat(
|
||||
calendar.getCapacityDurationAt(MONDAY_LOCAL_DATE.minusWeeks(1)),
|
||||
equalTo(hours(8)));
|
||||
|
||||
assertThat(calendar.getCapacityAt(MONDAY_LOCAL_DATE
|
||||
.minusDays(1)), equalTo(0));
|
||||
assertThat(
|
||||
calendar.getCapacityDurationAt(MONDAY_LOCAL_DATE.minusDays(1)),
|
||||
equalTo(zero()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -369,11 +385,11 @@ public class BaseCalendarTest {
|
|||
hours(8),
|
||||
createCalendarExceptionType());
|
||||
|
||||
assertThat(calendar
|
||||
.getCapacityAt(CHRISTMAS_DAY_LOCAL_DATE.plusYears(1)), equalTo(8));
|
||||
assertThat(calendar.getCapacityDurationAt(CHRISTMAS_DAY_LOCAL_DATE
|
||||
.plusYears(1)), equalTo(hours(8)));
|
||||
|
||||
assertThat(calendar
|
||||
.getCapacityAt(CHRISTMAS_DAY_LOCAL_DATE), equalTo(0));
|
||||
assertThat(calendar.getCapacityDurationAt(CHRISTMAS_DAY_LOCAL_DATE),
|
||||
equalTo(zero()));
|
||||
}
|
||||
|
||||
public static void setHoursForAllDays(BaseCalendar calendar, Integer hours) {
|
||||
|
|
@ -394,11 +410,14 @@ public class BaseCalendarTest {
|
|||
calendar.newVersion(FRIDAY_LOCAL_DATE);
|
||||
setHoursForAllDays(calendar, 2);
|
||||
|
||||
assertThat(calendar.getCapacityAt(MONDAY_LOCAL_DATE), equalTo(8));
|
||||
assertThat(calendar.getCapacityDurationAt(MONDAY_LOCAL_DATE),
|
||||
equalTo(hours(8)));
|
||||
|
||||
assertThat(calendar.getCapacityAt(WEDNESDAY_LOCAL_DATE), equalTo(4));
|
||||
assertThat(calendar.getCapacityDurationAt(WEDNESDAY_LOCAL_DATE),
|
||||
equalTo(hours(4)));
|
||||
|
||||
assertThat(calendar.getCapacityAt(FRIDAY_LOCAL_DATE), equalTo(2));
|
||||
assertThat(calendar.getCapacityDurationAt(FRIDAY_LOCAL_DATE),
|
||||
equalTo(hours(2)));
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -412,16 +431,20 @@ public class BaseCalendarTest {
|
|||
calendar.newVersion(WEDNESDAY_LOCAL_DATE);
|
||||
setHoursForAllDays(calendar, 2);
|
||||
|
||||
assertThat(baseCalendar.getCapacityAt(MONDAY_LOCAL_DATE), equalTo(8));
|
||||
assertThat(baseCalendar.getCapacityDurationAt(MONDAY_LOCAL_DATE),
|
||||
equalTo(hours(8)));
|
||||
|
||||
assertThat(calendar.getCapacityAt(MONDAY_LOCAL_DATE), equalTo(4));
|
||||
assertThat(calendar.getCapacityDurationAt(MONDAY_LOCAL_DATE),
|
||||
equalTo(hours(4)));
|
||||
|
||||
assertThat(baseCalendar.getCapacityAt(FRIDAY_LOCAL_DATE), equalTo(8));
|
||||
assertThat(baseCalendar.getCapacityDurationAt(FRIDAY_LOCAL_DATE),
|
||||
equalTo(hours(8)));
|
||||
|
||||
assertThat(calendar.getCapacityAt(FRIDAY_LOCAL_DATE), equalTo(2));
|
||||
assertThat(calendar.getCapacityDurationAt(FRIDAY_LOCAL_DATE),
|
||||
equalTo(hours(2)));
|
||||
|
||||
assertThat(calendar.getCapacityAt(CHRISTMAS_DAY_LOCAL_DATE),
|
||||
equalTo(0));
|
||||
assertThat(calendar.getCapacityDurationAt(CHRISTMAS_DAY_LOCAL_DATE),
|
||||
equalTo(zero()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -448,7 +471,8 @@ public class BaseCalendarTest {
|
|||
|
||||
private void thenForAllDaysReturnsZero() {
|
||||
for (LocalDate localDate : DAYS_OF_A_WEEK_EXAMPLE) {
|
||||
assertThat(calendarFixture.getCapacityAt(localDate), equalTo(0));
|
||||
assertThat(calendarFixture.getCapacityDurationAt(localDate),
|
||||
equalTo(zero()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -547,8 +571,8 @@ public class BaseCalendarTest {
|
|||
calendar.setParent(parent);
|
||||
|
||||
assertThat(calendar.getParent(), equalTo(parent));
|
||||
assertThat(calendar.getCapacityAt(CHRISTMAS_DAY_LOCAL_DATE),
|
||||
equalTo(0));
|
||||
assertThat(calendar.getCapacityDurationAt(CHRISTMAS_DAY_LOCAL_DATE),
|
||||
equalTo(zero()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -557,7 +581,8 @@ public class BaseCalendarTest {
|
|||
BaseCalendar derived = calendar.newDerivedCalendar();
|
||||
BaseCalendar copy = derived.newCopy();
|
||||
|
||||
assertThat(copy.getCapacityAt(CHRISTMAS_DAY_LOCAL_DATE), equalTo(0));
|
||||
assertThat(copy.getCapacityDurationAt(CHRISTMAS_DAY_LOCAL_DATE),
|
||||
equalTo(zero()));
|
||||
assertThat(copy.getParent(), equalTo(calendar));
|
||||
assertThat(copy.getCalendarDataVersions().size(), equalTo(1));
|
||||
}
|
||||
|
|
@ -584,11 +609,11 @@ public class BaseCalendarTest {
|
|||
assertThat(calendar.getParent(MONDAY_LOCAL_DATE),
|
||||
equalTo(parent1));
|
||||
|
||||
assertThat(calendar.getCapacityAt(MONDAY_LOCAL_DATE),
|
||||
equalTo(8));
|
||||
assertThat(calendar.getCapacityDurationAt(MONDAY_LOCAL_DATE),
|
||||
equalTo(hours(8)));
|
||||
|
||||
assertThat(calendar.getCapacityAt(FRIDAY_LOCAL_DATE),
|
||||
equalTo(4));
|
||||
assertThat(calendar.getCapacityDurationAt(FRIDAY_LOCAL_DATE),
|
||||
equalTo(hours(4)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -601,11 +626,11 @@ public class BaseCalendarTest {
|
|||
calendar.addExceptionDay(CalendarException.create(FRIDAY_LOCAL_DATE,
|
||||
zero(), createCalendarExceptionType()));
|
||||
|
||||
assertThat(calendar.getCapacityAt(MONDAY_LOCAL_DATE),
|
||||
equalTo(0));
|
||||
assertThat(calendar.getCapacityDurationAt(MONDAY_LOCAL_DATE),
|
||||
equalTo(zero()));
|
||||
|
||||
assertThat(calendar.getCapacityAt(FRIDAY_LOCAL_DATE),
|
||||
equalTo(0));
|
||||
assertThat(calendar.getCapacityDurationAt(FRIDAY_LOCAL_DATE),
|
||||
equalTo(zero()));
|
||||
|
||||
assertThat(calendar.getOwnExceptions().size(), equalTo(2));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import org.joda.time.LocalDate;
|
|||
import org.junit.Test;
|
||||
import org.navalplanner.business.calendars.entities.CombinedWorkHours;
|
||||
import org.navalplanner.business.calendars.entities.IWorkHours;
|
||||
import org.navalplanner.business.workingday.EffortDuration;
|
||||
|
||||
public class CombinedWorkHoursTest {
|
||||
|
||||
|
|
@ -57,13 +58,16 @@ public class CombinedWorkHoursTest {
|
|||
public void returnsTheMinOfCalendars() {
|
||||
IWorkHours minOf = CombinedWorkHours
|
||||
.minOf(hours(4), hours(2), hours(7));
|
||||
Integer hours = minOf.getCapacityAt(new LocalDate(2000, 3, 3));
|
||||
assertThat(hours, equalTo(2));
|
||||
EffortDuration duration = minOf.getCapacityDurationAt(new LocalDate(
|
||||
2000, 3, 3));
|
||||
assertThat(duration, equalTo(EffortDuration.hours(2)));
|
||||
}
|
||||
|
||||
private IWorkHours hours(int hours) {
|
||||
IWorkHours result = createNiceMock(IWorkHours.class);
|
||||
expect(result.getCapacityAt(isA(LocalDate.class))).andReturn(hours);
|
||||
expect(result.getCapacityDurationAt(isA(LocalDate.class))).andReturn(
|
||||
EffortDuration.hours(hours));
|
||||
replay(result);
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,8 +66,10 @@ public class ResourceCalendarTest {
|
|||
public void testGetWorkableHours() {
|
||||
ResourceCalendar calendar = createBasicResourceCalendar();
|
||||
|
||||
assertThat(calendar.getCapacityAt(PAST), equalTo(0));
|
||||
assertThat(calendar.getCapacityAt(FUTURE), equalTo(8));
|
||||
assertThat(calendar.getCapacityDurationAt(PAST),
|
||||
equalTo(EffortDuration.zero()));
|
||||
assertThat(calendar.getCapacityDurationAt(FUTURE),
|
||||
equalTo(EffortDuration.hours(8)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
|
|
|
|||
|
|
@ -80,6 +80,8 @@ public class SpecificResourceAllocationTest {
|
|||
this.calendar = createNiceMock(ResourceCalendar.class);
|
||||
expect(this.calendar.getCapacityAt(isA(LocalDate.class))).andReturn(
|
||||
hours).anyTimes();
|
||||
expect(this.calendar.getCapacityDurationAt(isA(LocalDate.class)))
|
||||
.andReturn(EffortDuration.hours(hours)).anyTimes();
|
||||
expect(this.calendar.getWorkableHours(isA(Date.class)))
|
||||
.andReturn(hours).anyTimes();
|
||||
expect(this.calendar.toHours(isA(LocalDate.class),
|
||||
|
|
@ -106,15 +108,28 @@ public class SpecificResourceAllocationTest {
|
|||
|
||||
private void givenResourceCalendar(final int defaultAnswer, final Map<LocalDate, Integer> answersForDates){
|
||||
this.calendar = createNiceMock(ResourceCalendar.class);
|
||||
expect(this.calendar.getCapacityDurationAt(isA(LocalDate.class)))
|
||||
.andAnswer(new IAnswer<EffortDuration>() {
|
||||
|
||||
@Override
|
||||
public EffortDuration answer() throws Throwable {
|
||||
LocalDate date = (LocalDate) EasyMock
|
||||
.getCurrentArguments()[0];
|
||||
if (answersForDates.containsKey(date)) {
|
||||
return EffortDuration.hours(answersForDates
|
||||
.get(date));
|
||||
}
|
||||
return EffortDuration.hours(defaultAnswer);
|
||||
}
|
||||
}).anyTimes();
|
||||
expect(this.calendar.getCapacityAt(isA(LocalDate.class))).andAnswer(new IAnswer<Integer>() {
|
||||
|
||||
@Override
|
||||
public Integer answer() throws Throwable {
|
||||
LocalDate date = (LocalDate) EasyMock.getCurrentArguments()[0];
|
||||
if(answersForDates.containsKey(date)){
|
||||
return answersForDates.get(date);
|
||||
}
|
||||
return defaultAnswer;
|
||||
LocalDate date = (LocalDate) EasyMock
|
||||
.getCurrentArguments()[0];
|
||||
return BaseCalendar.roundToHours(calendar
|
||||
.getCapacityDurationAt(date));
|
||||
}
|
||||
}).anyTimes();
|
||||
expect(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue