ForexSwapDefinition implements InstrumentDefinition<InstrumentDerivative> { @Override public InstrumentDerivative toDerivative(final ZonedDateTime date) { ArgumentChecker.isTrue(!date.isAfter(_farLeg.getExchangeDate()), "date is after payment far date"); if (date.isAfter(_nearLeg.getExchangeDate())) { return _farLeg.toDerivative(date); } final Forex nearLeg = _nearLeg.toDerivative(date); final Forex farLeg = _farLeg.toDerivative(date); return new ForexSwap(nearLeg, farLeg); } ForexSwapDefinition(final ForexDefinition nearLeg, final ForexDefinition farLeg);  ForexSwapDefinition(final Currency currency1, final Currency currency2, final ZonedDateTime nearDate, final ZonedDateTime farDate, final double amount1,
      final double forexRate, final double forwardPoints); ForexDefinition getNearLeg(); ForexDefinition getFarLeg(); @Override InstrumentDerivative toDerivative(final ZonedDateTime date); @Override V accept(final InstrumentDefinitionVisitor<U, V> visitor, final U data); @Override V accept(final InstrumentDefinitionVisitor<?, V> visitor); @Override int hashCode(); @Override boolean equals(final Object obj);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void toDerivativeWrongDate() { FX_SWAP_DEFINITION_FIN.toDerivative(FAR_DATE.plusDays(1)); }
@Test public void toDerivative() { final Forex fxNear = FX_NEAR_DEFINITION.toDerivative(REFERENCE_DATE); final Forex fxFar = FX_FAR_DEFINITION.toDerivative(REFERENCE_DATE); final ForexSwap fxSwapExpected = new ForexSwap(fxNear, fxFar); final InstrumentDerivative fxSwap = FX_SWAP_DEFINITION_FIN.toDerivative(REFERENCE_DATE); assertEquals(fxSwapExpected, fxSwap); }