ItEr21S10CUAltaCalendarioLaboral: Improved functionality of add and remove exception days method. In order to add or remove the method in the right calendar.
Added one new test, to check this behaviour.
This commit is contained in:
parent
00885e8385
commit
add2e68494
2 changed files with 37 additions and 10 deletions
|
|
@ -192,11 +192,18 @@ public class BaseCalendar extends BaseEntity implements IValidable {
|
|||
|
||||
public void addExceptionDay(ExceptionDay day)
|
||||
throws IllegalArgumentException {
|
||||
if (isExceptionDayAlreadyInExceptions(day)) {
|
||||
throw new IllegalArgumentException(
|
||||
"This day is already in the exception days");
|
||||
if (shouldUsePreviousCalendar(day.getDate())) {
|
||||
previousCalendar.addExceptionDay(day);
|
||||
} else if (shouldUseNextCalendar(day.getDate())) {
|
||||
nextCalendar.addExceptionDay(day);
|
||||
} else {
|
||||
if (isExceptionDayAlreadyInExceptions(day)) {
|
||||
throw new IllegalArgumentException(
|
||||
"This day is already in the exception days");
|
||||
}
|
||||
|
||||
exceptions.add(day);
|
||||
}
|
||||
exceptions.add(day);
|
||||
}
|
||||
|
||||
public void removeExceptionDay(Date date) throws IllegalArgumentException {
|
||||
|
|
@ -205,14 +212,19 @@ public class BaseCalendar extends BaseEntity implements IValidable {
|
|||
|
||||
public void removeExceptionDay(LocalDate date)
|
||||
throws IllegalArgumentException {
|
||||
if (shouldUsePreviousCalendar(date)) {
|
||||
previousCalendar.removeExceptionDay(date);
|
||||
} else if (shouldUseNextCalendar(date)) {
|
||||
nextCalendar.removeExceptionDay(date);
|
||||
} else {
|
||||
ExceptionDay day = getExceptionDay(date);
|
||||
if (day == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"There is not an exception day on that date");
|
||||
}
|
||||
|
||||
ExceptionDay day = getExceptionDay(date);
|
||||
if (day == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"There is not an exception day on that date");
|
||||
exceptions.remove(day);
|
||||
}
|
||||
|
||||
exceptions.remove(day);
|
||||
}
|
||||
|
||||
public void updateExceptionDay(LocalDate date, Integer hours)
|
||||
|
|
|
|||
|
|
@ -379,4 +379,19 @@ public class BaseCalendarTest {
|
|||
.getWorkableHours(CHRISTMAS_DAY_LOCAL_DATE)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddExceptionToNewVersionCalendar() {
|
||||
BaseCalendar calendar = createBasicCalendar();
|
||||
BaseCalendar newVersion = calendar.newVersion(CHRISTMAS_DAY_LOCAL_DATE
|
||||
.plusDays(1));
|
||||
|
||||
ExceptionDay day = ExceptionDay.create(CHRISTMAS_DAY_LOCAL_DATE, 0);
|
||||
newVersion.addExceptionDay(day);
|
||||
|
||||
assertThat(calendar.getExceptions().size(), equalTo(1));
|
||||
assertThat(newVersion.getExceptions().size(), equalTo(0));
|
||||
assertThat(calendar.getExceptions().iterator().next().getDate(),
|
||||
equalTo(CHRISTMAS_DAY_LOCAL_DATE));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue