GoldFutureExpiryCalculator implements ExchangeTradedInstrumentExpiryCalculator { @Override public LocalDate getExpiryDate(final int n, final LocalDate today, final Calendar holidayCalendar) { ArgumentChecker.isTrue(n > 0, "n must be greater than zero; have {}", n); ArgumentChecker.notNull(today, "today"); ArgumentChecker.notNull(holidayCalendar, "holiday calendar"); LocalDate expiryDate = getExpiryMonth(n, today).with(LAST_DAY_ADJUSTER); int nBusinessDays = 3; if (holidayCalendar.isWorkingDay(expiryDate)) { nBusinessDays--; } while (nBusinessDays > 0) { expiryDate = expiryDate.minusDays(1); if (holidayCalendar.isWorkingDay(expiryDate)) { nBusinessDays--; } } return expiryDate; } private  GoldFutureExpiryCalculator(); static GoldFutureExpiryCalculator getInstance(); @Override LocalDate getExpiryDate(final int n, final LocalDate today, final Calendar holidayCalendar); @Override LocalDate getExpiryMonth(final int n, final LocalDate today); @Override String getName(); static final String NAME; }
@Test public void getExpiryDate() { assertEquals(LocalDate.of(2013, 2, 26), EXPIRY_CALC.getExpiryDate(1, DATE, WEEKEND_CALENDAR)); assertEquals(LocalDate.of(2013, 3, 27), EXPIRY_CALC.getExpiryDate(2, DATE, WEEKEND_CALENDAR)); assertEquals(LocalDate.of(2013, 4, 26), EXPIRY_CALC.getExpiryDate(3, DATE, WEEKEND_CALENDAR)); assertEquals(LocalDate.of(2013, 6, 26), EXPIRY_CALC.getExpiryDate(4, DATE, WEEKEND_CALENDAR)); assertEquals(LocalDate.of(2013, 8, 28), EXPIRY_CALC.getExpiryDate(5, DATE, WEEKEND_CALENDAR)); assertEquals(LocalDate.of(2013, 10, 29), EXPIRY_CALC.getExpiryDate(6, DATE, WEEKEND_CALENDAR)); assertEquals(LocalDate.of(2013, 12, 27), EXPIRY_CALC.getExpiryDate(7, DATE, WEEKEND_CALENDAR)); }