### Question:
DateTimePeriod { public List<DateTimePeriod> toMonths() { ArrayList<DateTimePeriod> list = new ArrayList<DateTimePeriod>(); DateTime currentStart = getStart(); DateTime nextStart = currentStart.plusMonths(1); while (nextStart.isBefore(getEnd()) || nextStart.isEqual(getEnd())) { list.add(new DateTimeMonth(currentStart, nextStart)); currentStart = nextStart; nextStart = currentStart.plusMonths(1); } return list; } protected  DateTimePeriod(DateTime start, DateTime end, DateTimeDuration duration, String keyPattern,
            String longNamePattern, String shortNamePattern, String indexNamePattern); DateTime getStart(); DateTime getEnd(); DateTimeDuration getDuration(); String getKey(); String getLongName(); String getShortName(); String getIndexName(); abstract DateTimePeriod getNext(); abstract DateTimePeriod getPrevious(); abstract DateTimeDuration getDefaultSubDuration(); List<DateTimePeriod> toPeriods(DateTimeDuration duration); List<DateTimePeriod> toFiveMinutes(); List<DateTimePeriod> toHours(); List<DateTimePeriod> toDays(); List<DateTimePeriod> toMonths(); List<DateTimePeriod> toYears(); @Override boolean equals(Object object); @Override int hashCode(); static DateTimePeriod create(DateTimeDuration duration, DateTime start); static DateTimePeriod createYear(int year, DateTimeZone zone); static DateTimePeriod createYear(DateTime start); static DateTimePeriod createMonth(int year, int month, DateTimeZone zone); static DateTimePeriod createMonth(DateTime start); static DateTimePeriod createDay(int year, int month, int day, DateTimeZone zone); static DateTimePeriod createDay(DateTime start); static DateTimePeriod createHour(int year, int month, int day, int hour, DateTimeZone zone); static DateTimePeriod createHour(DateTime start); static DateTimePeriod createFiveMinutes(int year, int month, int day, int hour, int minute, DateTimeZone zone); static DateTimePeriod createFiveMinutes(DateTime start); static List<DateTimePeriod> createLastYearMonths(DateTimeZone zone);  }### Answer:
@Test public void toMonths() throws Exception { DateTimePeriod period0 = DateTimePeriod.createMonth(2009, 1, DateTimeZone.UTC); List<DateTimePeriod> periods = period0.toMonths(); Assert.assertArrayEquals(new DateTimePeriod[] { DateTimePeriod.createMonth(2009, 1, DateTimeZone.UTC) }, periods.toArray(new DateTimePeriod[0])); period0 = new DateTimeMonth(new DateTime(2009,1,1,0,0,0,0,DateTimeZone.UTC), new DateTime(2009,3,1,1,0,0,0,DateTimeZone.UTC)); periods = period0.toPeriods(DateTimeDuration.MONTH); Assert.assertArrayEquals(new DateTimePeriod[] { DateTimePeriod.createMonth(2009, 1, DateTimeZone.UTC), DateTimePeriod.createMonth(2009, 2, DateTimeZone.UTC) }, periods.toArray(new DateTimePeriod[0])); period0 = DateTimePeriod.createDay(2009, 1, 1, DateTimeZone.UTC); periods = period0.toMonths(); Assert.assertArrayEquals(new DateTimePeriod[] {}, periods.toArray(new DateTimePeriod[0])); }