@Test
  public void shouldInsertPeriodWithAllData() throws Exception {
    Date date1 = new Date();
    Date date2 = new Date(date1.getTime() + 90 * 24 * 60 * 60 * 1000);

    ProcessingPeriod period1 =
        make(
            a(
                defaultProcessingPeriod,
                with(scheduleId, schedule.getId()),
                with(ProcessingPeriodBuilder.startDate, date1),
                with(endDate, date2),
                with(numberOfMonths, 3)));

    Integer insertCount = mapper.insert(period1);

    assertThat(insertCount, is(1));
    ProcessingPeriod insertedPeriod = mapper.getAll(schedule.getId()).get(0);
    assertThat(insertedPeriod.getName(), is("Month1"));
    assertThat(insertedPeriod.getDescription(), is("first month"));
    assertThat(insertedPeriod.getStartDate(), is(date1));
    assertThat(insertedPeriod.getEndDate(), is(date2));
    assertThat(insertedPeriod.getNumberOfMonths(), is(3));
    assertThat(insertedPeriod.getModifiedBy(), is(1L));
    assertThat(insertedPeriod.getModifiedDate(), is(notNullValue()));
  }
 public Integer findM(ProcessingPeriod currentPeriod) {
   List<ProcessingPeriod> nPreviousPeriods =
       periodRepository.getNPreviousPeriods(currentPeriod, 1);
   if (nPreviousPeriods.size() > 0) {
     return nPreviousPeriods.get(0).getNumberOfMonths();
   }
   return currentPeriod.getNumberOfMonths();
 }