@Test
public void testInterval() {
Calendar calendar = Calendar.getInstance();
Calendar endCalendar = Calendar.getInstance();
Interval interval = new Interval("month_to_date");
assertNotNull("Interval MONTH instanced", interval);
calendar.setTime(interval.getFrom());
endCalendar.setTime(interval.getTo());
assertEquals("First day of month", 1, calendar.get(Calendar.DAY_OF_MONTH));
assertEquals("Same month", calendar.get(Calendar.MONTH), endCalendar.get(Calendar.MONTH));
interval = new Interval("year_to_date");
assertNotNull("Interval YEAR instanced", interval);
calendar.setTime(interval.getFrom());
endCalendar.setTime(interval.getTo());
assertEquals("First day of year", 1, calendar.get(Calendar.DAY_OF_MONTH));
assertEquals("First day of year(January)", 0, calendar.get(Calendar.MONTH));
assertEquals("Same year", calendar.get(Calendar.YEAR), endCalendar.get(Calendar.YEAR));
interval = new Interval(Intervals.LAST_QUARTER);
assertNotNull("Interval QUARTER instanced", interval);
calendar.setTime(interval.getFrom());
endCalendar.setTime(interval.getTo());
calendar.add(Calendar.MONTH, 3);
assertEquals("Three months before", calendar.get(Calendar.MONTH) , endCalendar.get(Calendar.MONTH));
interval = new Interval(Intervals.PREVIOUS_MONTH);
assertNotNull("Interval PMONTH instanced", interval);
calendar.setTime(interval.getFrom());
endCalendar.setTime(interval.getTo());
assertEquals("First day of previous month", 1, calendar.get(Calendar.DAY_OF_MONTH));
Calendar pmonth = Calendar.getInstance();
pmonth.add(Calendar.MONTH, -1);
assertEquals("Last day of previous month", pmonth.getActualMaximum(Calendar.DAY_OF_MONTH), endCalendar.get(Calendar.DAY_OF_MONTH));
assertEquals("Same month", calendar.get(Calendar.MONTH), endCalendar.get(Calendar.MONTH));
assertEquals("Last month", pmonth.get(Calendar.MONTH), endCalendar.get(Calendar.MONTH));
interval = new Interval(Intervals.PREVIOUS_YEAR);
assertNotNull("Interval PYEAR instanced", interval);
calendar.setTime(interval.getFrom());
endCalendar.setTime(interval.getTo());
assertEquals("Same year (before)", calendar.get(Calendar.YEAR) , endCalendar.get(Calendar.YEAR));
Calendar pyear = Calendar.getInstance();
pyear.add(Calendar.MONTH, -1);
assertEquals("One year before", calendar.get(Calendar.YEAR) + 1, pyear.get(Calendar.YEAR));
interval = new Interval(null, null);
assertNotNull("Null from converted", interval.getFrom());
assertNotNull("Null to converted", interval.getTo());
}