OptionDefinition { public double getTimeToExpiry(final ZonedDateTime date) { if (date.isAfter(getExpiry().getExpiry())) { throw new IllegalArgumentException("Date " + date + " is after expiry " + getExpiry()); } return DateUtils.getDifferenceInYears(date, getExpiry().getExpiry()); } OptionDefinition(final Double strike, final Expiry expiry, final Boolean isCall); Double getStrike(); Expiry getExpiry(); double getTimeToExpiry(final ZonedDateTime date); Boolean isCall(); abstract OptionExerciseFunction<T> getExerciseFunction(); abstract OptionPayoffFunction<T> getPayoffFunction(); @Override int hashCode(); @Override boolean equals(final Object obj);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testDateAfterExpiry() { DEFINITION.getTimeToExpiry(DateUtils.getDateOffsetWithYearFraction(DATE, YEARS * 2)); }