AbstractDateSelectionModel implements DateSelectionModel { @Override public void setLowerBound(Date lowerBound) { if (lowerBound != null) { lowerBound = getNormalizedDate(lowerBound); } if (CalendarUtils.areEqual(lowerBound, getLowerBound())) return; this.lowerBound = lowerBound; if (this.lowerBound != null && !isSelectionEmpty()) { long justBelowLowerBoundMs = this.lowerBound.getTime() - 1; removeSelectionInterval(getFirstSelectionDate(), new Date( justBelowLowerBoundMs)); } fireValueChanged(EventType.LOWER_BOUND_CHANGED); } AbstractDateSelectionModel();  AbstractDateSelectionModel(Locale locale); @Override Calendar getCalendar(); @Override int getFirstDayOfWeek(); @Override void setFirstDayOfWeek(final int firstDayOfWeek); @Override int getMinimalDaysInFirstWeek(); @Override void setMinimalDaysInFirstWeek(int minimalDays); @Override TimeZone getTimeZone(); @Override void setTimeZone(TimeZone timeZone); @Override Locale getLocale(); @Override void setLocale(Locale locale); @Override Date getUpperBound(); @Override void setUpperBound(Date upperBound); @Override Date getLowerBound(); @Override void setLowerBound(Date lowerBound); @Override boolean isAdjusting(); @Override void setAdjusting(boolean adjusting); @Override void addDateSelectionListener(DateSelectionListener l); @Override void removeDateSelectionListener(DateSelectionListener l); List<DateSelectionListener> getDateSelectionListeners(); static final SortedSet<Date> EMPTY_DATES; }
@Test public void testSetLowerBoundSameNotFire() { model.setLowerBound(today); DateSelectionReport report = new DateSelectionReport(model); model.setLowerBound(today); assertEquals("same bound, no event fired", 0, report.getEventCount()); }
@Test public void testSetLowerBoundFireRemove() { model.setLowerBound(today); DateSelectionReport report = new DateSelectionReport(model); model.setLowerBound(null); assertEquals("bound changed, event must be fired", 1, report.getEventCount(EventType.LOWER_BOUND_CHANGED)); }
@Test public void testSetLowerBoundFireSet() { DateSelectionReport report = new DateSelectionReport(model); model.setLowerBound(today); assertEquals("bound changed, event must be fired", 1, report.getEventCount(EventType.LOWER_BOUND_CHANGED)); }
@Test public void testSetLowerBoundNPE() { model.setLowerBound(yesterday); model.setSelectionInterval(today, today); model.setLowerBound(null); }
@Test public void testSetLowerBoundClearsSelectionBefore() { model.setSelectionInterval(yesterday, yesterday); model.setLowerBound(today); assertTrue("past selection must be cleared", model.isSelectionEmpty()); }
@Test public void testLowerBoundAllowedPastBlocked() { model.setLowerBound(today); model.setSelectionInterval(today, today); assertFalse("lower bound is selectable", model.isSelectionEmpty()); assertTrue("loweer bound must be selected", model.isSelected(today)); DateSelectionReport report = new DateSelectionReport(model); model.setSelectionInterval(yesterday, yesterday); assertFalse("past must not be selected", model.isSelected(yesterday)); assertEquals("no event fired", 0, report.getEventCount()); model.setLowerBound(null); model.setSelectionInterval(yesterday, yesterday); assertTrue("past must be selected after removing lower bound ", model.isSelected(yesterday)); }