ProjectActivity implements Serializable, Comparable<ProjectActivity> { public void setEndTime(final int hours, final int minutes) { DateTime endDate = getEnd(); if (hours == endDate.getHourOfDay() && minutes == endDate.getMinuteOfHour()) { return; } if (endDate.getHourOfDay() == 0 && endDate.getMinuteOfHour() == 0) { endDate = endDate.minusDays(1); } else if (hours == 0 && minutes == 0) { endDate = endDate.plusDays(1); } endDate = endDate.withHourOfDay(hours).withMinuteOfHour(minutes); if (endDate.isBefore(getStart())) { throw new IllegalArgumentException("End time may not be before start time!"); } this.end = endDate; } ProjectActivity(final DateTime start, final DateTime end, final Project project);  ProjectActivity(final DateTime start, final DateTime end, final Project project,
            final String description); long getId(); void setId(long id); String getDescription(); void setDescription(final String description); void setDay(final DateTime day); DateTime getDay(); DateTime getEnd(); void setEndTime(final int hours, final int minutes); Project getProject(); void setProject(final Project project); DateTime getStart(); void setStartTime(final int hours, final int minutes); @Override String toString(); @Override int compareTo(final ProjectActivity activity); final double getDuration(); static final String PROPERTY_START; static final String PROPERTY_END; static final String PROPERTY_DATE; static final String PROPERTY_PROJECT; static final String PROPERTY_DESCRIPTION; }
@Test public void testStartNotAfterEnd() { try { new ProjectActivity(new DateTime(2009, 1, 1, 13, 0, 0 ,0), new DateTime(2009, 1, 1, 12, 0, 0, 0), null); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } try { ProjectActivity act = new ProjectActivity(new DateTime(2009, 1, 1, 11, 0, 0 ,0), new DateTime(2009, 1, 1, 12, 0, 0, 0), null); act.setEndTime(10, 0); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } try { ProjectActivity act = new ProjectActivity(new DateTime(2009, 1, 1, 11, 0, 0 ,0), new DateTime(2009, 1, 1, 12, 0, 0, 0), null); act.setEndTime(13, 0); } catch (IllegalArgumentException e) { fail("Unexpected IllegalArgumentException"); } }