AbstractDateSelectionModel implements DateSelectionModel { @Override public void setUpperBound(Date upperBound) { if (upperBound != null) { upperBound = getNormalizedDate(upperBound); } if (CalendarUtils.areEqual(upperBound, getUpperBound())) return; this.upperBound = upperBound; if (this.upperBound != null && !isSelectionEmpty()) { long justAboveUpperBoundMs = this.upperBound.getTime() + 1; removeSelectionInterval(new Date(justAboveUpperBoundMs), getLastSelectionDate()); } fireValueChanged(EventType.UPPER_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 testSetUpperBoundSameNotFire() { model.setUpperBound(today); DateSelectionReport report = new DateSelectionReport(model); model.setUpperBound(today); assertEquals("same bound, no event fired", 0, report.getEventCount()); }
@Test public void testSetUpperBoundFireRemove() { model.setUpperBound(today); DateSelectionReport report = new DateSelectionReport(model); model.setUpperBound(null); assertEquals("bound changed, event must be fired", 1, report.getEventCount(EventType.UPPER_BOUND_CHANGED)); }
@Test public void testSetUpperBoundFireSet() { DateSelectionReport report = new DateSelectionReport(model); model.setUpperBound(today); assertEquals("bound changed, event must be fired", 1, report.getEventCount(EventType.UPPER_BOUND_CHANGED)); }
@Test public void testSetUpperBoundNPE() { model.setUpperBound(today); model.setSelectionInterval(yesterday, yesterday); model.setUpperBound(null); }
@Test public void testSetUpperBoundClearsSelectionAfter() { model.setSelectionInterval(tomorrow, tomorrow); model.setUpperBound(today); assertTrue("future selection must be cleared", model.isSelectionEmpty()); }
@Test public void testUpperBoundAllowedFutureBlocked() { model.setUpperBound(today); model.setSelectionInterval(today, today); assertFalse("upper bound is selectable", model.isSelectionEmpty()); assertTrue("upper bound must be selected", model.isSelected(today)); DateSelectionReport report = new DateSelectionReport(model); model.setSelectionInterval(tomorrow, tomorrow); assertFalse("future must not be selected", model.isSelected(tomorrow)); assertEquals("no event fired", 0, report.getEventCount()); model.setUpperBound(null); model.setSelectionInterval(tomorrow, tomorrow); assertTrue("tomorrow must be selected after removing upper bound ", model.isSelected(tomorrow)); }