### Question:
DispatchingSwapPaymentPeriodPricer implements SwapPaymentPeriodPricer<SwapPaymentPeriod> { @Override public double presentValue(SwapPaymentPeriod paymentPeriod, RatesProvider provider) { if (paymentPeriod instanceof RatePaymentPeriod) { return ratePaymentPeriodPricer.presentValue((RatePaymentPeriod) paymentPeriod, provider); } else if (paymentPeriod instanceof KnownAmountSwapPaymentPeriod) { return knownAmountPaymentPeriodPricer.presentValue((KnownAmountSwapPaymentPeriod) paymentPeriod, provider); } else { throw new IllegalArgumentException("Unknown PaymentPeriod type: " + paymentPeriod.getClass().getSimpleName()); } } DispatchingSwapPaymentPeriodPricer(
      SwapPaymentPeriodPricer<RatePaymentPeriod> ratePaymentPeriodPricer,
      SwapPaymentPeriodPricer<KnownAmountSwapPaymentPeriod> knownAmountPaymentPeriodPricer); @Override double presentValue(SwapPaymentPeriod paymentPeriod, RatesProvider provider); @Override PointSensitivityBuilder presentValueSensitivity(SwapPaymentPeriod paymentPeriod, RatesProvider provider); @Override double forecastValue(SwapPaymentPeriod paymentPeriod, RatesProvider provider); @Override PointSensitivityBuilder forecastValueSensitivity(SwapPaymentPeriod paymentPeriod, RatesProvider provider); @Override double pvbp(SwapPaymentPeriod paymentPeriod, RatesProvider provider); @Override PointSensitivityBuilder pvbpSensitivity(SwapPaymentPeriod paymentPeriod, RatesProvider provider); @Override double accruedInterest(SwapPaymentPeriod paymentPeriod, RatesProvider provider); @Override void explainPresentValue(SwapPaymentPeriod paymentPeriod, RatesProvider provider, ExplainMapBuilder builder); @Override MultiCurrencyAmount currencyExposure(SwapPaymentPeriod paymentPeriod, RatesProvider provider); @Override double currentCash(SwapPaymentPeriod paymentPeriod, RatesProvider provider); static final DispatchingSwapPaymentPeriodPricer DEFAULT; }### Answer:
@Test public void test_presentValue_RatePaymentPeriod() { double expected = 0.0123d; SwapPaymentPeriodPricer<RatePaymentPeriod> mockNotionalExchangeFn = mock(SwapPaymentPeriodPricer.class); when(mockNotionalExchangeFn.presentValue(SwapDummyData.FIXED_RATE_PAYMENT_PERIOD_REC_GBP, MOCK_PROV)) .thenReturn(expected); DispatchingSwapPaymentPeriodPricer test = new DispatchingSwapPaymentPeriodPricer(mockNotionalExchangeFn, MOCK_KNOWN); assertThat(test.presentValue(SwapDummyData.FIXED_RATE_PAYMENT_PERIOD_REC_GBP, MOCK_PROV)).isCloseTo(expected, offset(0d)); }
@Test public void test_presentValue_unknownType() { SwapPaymentPeriod mockPaymentPeriod = mock(SwapPaymentPeriod.class); DispatchingSwapPaymentPeriodPricer test = DispatchingSwapPaymentPeriodPricer.DEFAULT; assertThatIllegalArgumentException() .isThrownBy(() -> test.presentValue(mockPaymentPeriod, MOCK_PROV)); }