ReportMonth { public LocalDate startOfCurrentReportMonth(LocalDate date) { if (date.getDayOfMonth() >= REPORTING_MONTH_START_DAY) { return new LocalDate(date.getYear(), date.getMonthOfYear(), REPORTING_MONTH_START_DAY); } if (date.getMonthOfYear() == JANUARY) { return new LocalDate(previousYear(date), DECEMBER, REPORTING_MONTH_START_DAY); } return new LocalDate(date.getYear(), previousMonth(date), REPORTING_MONTH_START_DAY); }  Date startDateOfReportingYear(); int reportingYear(); LocalDate startDateOfNextReportingMonth(LocalDate date); LocalDate endDateOfReportingMonthGivenStartDate(LocalDate startDate); LocalDate startOfCurrentReportMonth(LocalDate date); LocalDate endOfCurrentReportMonth(LocalDate date); boolean isDateWithinCurrentReportMonth(LocalDate lastReportedDate); int reportingMonth(LocalDate date); int reportingYear(LocalDate date); boolean areDatesBelongToSameReportingMonth(LocalDate date, LocalDate anotherDate);  }
@Test public void shouldCalculateStartOfCurrentReportMonth() throws Exception { assertEquals(LocalDate.parse("2011-11-26"), reportMonth.startOfCurrentReportMonth(LocalDate.parse("2011-11-28"))); assertEquals(LocalDate.parse("2011-12-26"), reportMonth.startOfCurrentReportMonth(LocalDate.parse("2011-12-26"))); assertEquals(LocalDate.parse("2011-12-26"), reportMonth.startOfCurrentReportMonth(LocalDate.parse("2011-12-27"))); assertEquals(LocalDate.parse("2011-12-26"), reportMonth.startOfCurrentReportMonth(LocalDate.parse("2012-01-01"))); assertEquals(LocalDate.parse("2012-01-26"), reportMonth.startOfCurrentReportMonth(LocalDate.parse("2012-01-26"))); assertEquals(LocalDate.parse("2012-01-26"), reportMonth.startOfCurrentReportMonth(LocalDate.parse("2012-01-27"))); assertEquals(LocalDate.parse("2012-01-26"), reportMonth.startOfCurrentReportMonth(LocalDate.parse("2012-02-01"))); assertEquals(LocalDate.parse("2012-03-26"), reportMonth.startOfCurrentReportMonth(LocalDate.parse("2012-03-31"))); assertEquals(LocalDate.parse("2012-01-26"), reportMonth.startOfCurrentReportMonth(LocalDate.parse("2012-02-25"))); assertEquals(LocalDate.parse("2012-02-26"), reportMonth.startOfCurrentReportMonth(LocalDate.parse("2012-02-26"))); assertEquals(LocalDate.parse("2012-02-26"), reportMonth.startOfCurrentReportMonth(LocalDate.parse("2012-02-27"))); }