ItEr23S08CUEdicionCalendarioLaboral: Checking that hours for a day are always positive.

This commit is contained in:
Manuel Rego Casasnovas 2009-08-25 10:20:05 +02:00 committed by Óscar González Fernández
parent f5ab5b66f8
commit 90a12b2f7a
3 changed files with 23 additions and 5 deletions

View file

@ -96,11 +96,17 @@ public class BaseCalendar extends BaseEntity implements IValidable {
return hours;
}
public void setHours(Days day, Integer hours) {
public void setHours(Days day, Integer hours)
throws IllegalArgumentException {
setHoursForDay(day, hours);
}
private void setHoursForDay(Days day, Integer hours) {
private void setHoursForDay(Days day, Integer hours)
throws IllegalArgumentException {
if ((hours != null) && (hours < 0)) {
throw new IllegalArgumentException(
"The number of hours for a day can not be negative");
}
hoursPerDay.put(day.ordinal(), hours);
}

View file

@ -532,4 +532,11 @@ public class BaseCalendarTest {
assertThat(copy.getPreviousCalendar(), nullValue());
}
@Test(expected = IllegalArgumentException.class)
public void testSetHoursInvalid() {
BaseCalendar calendar = createBasicCalendar();
calendar.setHours(Days.MONDAY, -5);
}
}

View file

@ -264,7 +264,8 @@ public class BaseCalendarCRUDController extends GenericForwardComposer {
item.appendChild(labelListcell);
Listcell hoursListcell = new Listcell();
Intbox hoursIntbox = Util.bind(new Intbox(),
final Intbox intBox = new Intbox();
Intbox hoursIntbox = Util.bind(intBox,
new Util.Getter<Integer>() {
@Override
@ -275,8 +276,12 @@ public class BaseCalendarCRUDController extends GenericForwardComposer {
@Override
public void set(Integer value) {
baseCalendarModel.setHours(day,
value);
try {
baseCalendarModel.setHours(day, value);
} catch (IllegalArgumentException e) {
throw new WrongValueException(intBox, e
.getMessage());
}
}
});