Date now = new Date();
Date start = new Date(now.getTime() - 1L);
Date end = new Date(now.getTime() + 1L);
Date preStart = new Date(now.getTime() - 2L);
Date postEnd = new Date(now.getTime() + 2L);
SpinnerDateModel m = new SpinnerDateModel(now, start, end, Calendar.YEAR);
harness.check(m.getValue(), now);
harness.check(m.getStart(), start);
harness.check(m.getEnd(), end);
harness.check(m.getCalendarField(), Calendar.YEAR);
// value equal to start
m = new SpinnerDateModel(start, start, end, Calendar.YEAR);
harness.check(m.getValue(), start);
harness.check(m.getStart(), start);
harness.check(m.getEnd(), end);
harness.check(m.getCalendarField(), Calendar.YEAR);
// value before start
boolean pass = false;
try
{
m = new SpinnerDateModel(preStart, start, end, Calendar.YEAR);
}
catch (IllegalArgumentException e)
{
pass = true;
}
harness.check(pass);
// value equal to end
m = new SpinnerDateModel(end, start, end, Calendar.YEAR);
harness.check(m.getValue(), end);
harness.check(m.getStart(), start);
harness.check(m.getEnd(), end);
harness.check(m.getCalendarField(), Calendar.YEAR);
// value above maximum
pass = false;
try
{
m = new SpinnerDateModel(postEnd, start, end, Calendar.YEAR);
}
catch (IllegalArgumentException e)
{
pass = true;
}
harness.check(pass);
// check null value
pass = false;
try
{
m = new SpinnerDateModel(null, start, end, Calendar.YEAR);
}
catch (IllegalArgumentException e)
{
pass = true;
}
harness.check(pass);
// check valid calendar fields
m = new SpinnerDateModel(now, start, end, Calendar.ERA);
harness.check(m.getCalendarField(), Calendar.ERA);
m = new SpinnerDateModel(now, start, end, Calendar.YEAR);
harness.check(m.getCalendarField(), Calendar.YEAR);
m = new SpinnerDateModel(now, start, end, Calendar.MONTH);
harness.check(m.getCalendarField(), Calendar.MONTH);
m = new SpinnerDateModel(now, start, end, Calendar.WEEK_OF_YEAR);
harness.check(m.getCalendarField(), Calendar.WEEK_OF_YEAR);
m = new SpinnerDateModel(now, start, end, Calendar.WEEK_OF_MONTH);
harness.check(m.getCalendarField(), Calendar.WEEK_OF_MONTH);
m = new SpinnerDateModel(now, start, end, Calendar.DAY_OF_MONTH);
harness.check(m.getCalendarField(), Calendar.DAY_OF_MONTH);
m = new SpinnerDateModel(now, start, end, Calendar.DAY_OF_YEAR);
harness.check(m.getCalendarField(), Calendar.DAY_OF_YEAR);
m = new SpinnerDateModel(now, start, end, Calendar.DAY_OF_WEEK);
harness.check(m.getCalendarField(), Calendar.DAY_OF_WEEK);
m = new SpinnerDateModel(now, start, end, Calendar.DAY_OF_WEEK_IN_MONTH);
harness.check(m.getCalendarField(), Calendar.DAY_OF_WEEK_IN_MONTH);
m = new SpinnerDateModel(now, start, end, Calendar.AM_PM);
harness.check(m.getCalendarField(), Calendar.AM_PM);
m = new SpinnerDateModel(now, start, end, Calendar.HOUR);
harness.check(m.getCalendarField(), Calendar.HOUR);
m = new SpinnerDateModel(now, start, end, Calendar.HOUR_OF_DAY);
harness.check(m.getCalendarField(), Calendar.HOUR_OF_DAY);
m = new SpinnerDateModel(now, start, end, Calendar.MINUTE);
harness.check(m.getCalendarField(), Calendar.MINUTE);
m = new SpinnerDateModel(now, start, end, Calendar.SECOND);
harness.check(m.getCalendarField(), Calendar.SECOND);
m = new SpinnerDateModel(now, start, end, Calendar.MILLISECOND);
harness.check(m.getCalendarField(), Calendar.MILLISECOND);
m = new SpinnerDateModel(now, start, end, Calendar.DATE);
harness.check(m.getCalendarField(), Calendar.DATE);
// check invalid calendar fields
pass = false;
try
{
m = new SpinnerDateModel(now, start, end, Calendar.DST_OFFSET);
}
catch (IllegalArgumentException e)
{
pass = true;
}
harness.check(pass);
pass = false;
try
{
m = new SpinnerDateModel(now, start, end, Calendar.ZONE_OFFSET);
}
catch (IllegalArgumentException e)
{
pass = true;
}