LoanDisbursementCoupledToCustomerMeetingScheduleStrategyImpl implements LoanDisbursementStrategy { @Override public LocalDate findClosestMatchingDateFromAndInclusiveOf(LocalDate fromAndInclusiveOf) { LocalDate closestMatch = nextValidCustomerMeetingDate; if (closestMatch.isBefore(fromAndInclusiveOf)) { closestMatch = new LocalDate(scheduledEvent.nextEventDateAfter(closestMatch.toDateMidnight().toDateTime())); while (closestMatch.isBefore(fromAndInclusiveOf)) { closestMatch = new LocalDate(scheduledEvent.nextEventDateAfter(closestMatch.toDateMidnight().toDateTime())); } } return closestMatch; } LoanDisbursementCoupledToCustomerMeetingScheduleStrategyImpl(ScheduledEvent scheduledEvent, LocalDate nextValidCustomerMeetingDate); @Override LocalDate findClosestMatchingDateFromAndInclusiveOf(LocalDate fromAndInclusiveOf); @Override boolean isDisbursementDateValidInRelationToSchedule(LocalDate disbursementDate);  }
@Test public void shouldFindNextMatchingDateInclusiveOfDateProvided() { LocalDate fromAndInclusiveOf = new LocalDate(); DateTime expectedDateTimeToStartSearchFrom = fromAndInclusiveOf.minusDays(1).toDateMidnight().toDateTime(); DateTime nextMatchingDate = new DateTime(); when(scheduledEvent.nextEventDateAfter(expectedDateTimeToStartSearchFrom)).thenReturn(nextMatchingDate); LocalDate result = loanDisbursementStrategy.findClosestMatchingDateFromAndInclusiveOf(fromAndInclusiveOf); assertThat(result, is(nextMatchingDate.toLocalDate())); }