### Question:
DispatchingSwapPaymentEventPricer implements SwapPaymentEventPricer<SwapPaymentEvent> { @Override public MultiCurrencyAmount currencyExposure(SwapPaymentEvent paymentEvent, RatesProvider provider) { if (paymentEvent instanceof NotionalExchange) { return notionalExchangePricer.currencyExposure((NotionalExchange) paymentEvent, provider); } else if (paymentEvent instanceof FxResetNotionalExchange) { return fxResetNotionalExchangePricer.currencyExposure((FxResetNotionalExchange) paymentEvent, provider); } else { throw new IllegalArgumentException("Unknown PaymentEvent type: " + paymentEvent.getClass().getSimpleName()); } } DispatchingSwapPaymentEventPricer(
      SwapPaymentEventPricer<NotionalExchange> notionalExchangePricer,
      SwapPaymentEventPricer<FxResetNotionalExchange> fxResetNotionalExchangePricer); @Override double presentValue(SwapPaymentEvent paymentEvent, RatesProvider provider); @Override PointSensitivityBuilder presentValueSensitivity(SwapPaymentEvent paymentEvent, RatesProvider provider); @Override double forecastValue(SwapPaymentEvent paymentEvent, RatesProvider provider); @Override PointSensitivityBuilder forecastValueSensitivity(SwapPaymentEvent paymentEvent, RatesProvider provider); @Override void explainPresentValue(SwapPaymentEvent paymentEvent, RatesProvider provider, ExplainMapBuilder builder); @Override MultiCurrencyAmount currencyExposure(SwapPaymentEvent paymentEvent, RatesProvider provider); @Override double currentCash(SwapPaymentEvent paymentEvent, RatesProvider provider); static final DispatchingSwapPaymentEventPricer DEFAULT; }### Answer:
@Test public void test_currencyExposure_NotionalExchange() { MultiCurrencyAmount expected = MultiCurrencyAmount.of(Currency.GBP, 0.0123d); SwapPaymentEventPricer<NotionalExchange> mockCalledFn = mock(SwapPaymentEventPricer.class); when(mockCalledFn.currencyExposure(SwapDummyData.NOTIONAL_EXCHANGE_REC_GBP, MOCK_PROV)) .thenReturn(expected); DispatchingSwapPaymentEventPricer test = new DispatchingSwapPaymentEventPricer( mockCalledFn, MOCK_FX_NOTIONAL_EXG); assertThat(test.currencyExposure(SwapDummyData.NOTIONAL_EXCHANGE_REC_GBP, MOCK_PROV)).isEqualTo(expected); }
@Test public void test_currencyExposure_FxResetNotionalExchange() { MultiCurrencyAmount expected = MultiCurrencyAmount.of(Currency.GBP, 0.0123d); SwapPaymentEventPricer<FxResetNotionalExchange> mockCalledFn = mock(SwapPaymentEventPricer.class); when(mockCalledFn.currencyExposure(SwapDummyData.FX_RESET_NOTIONAL_EXCHANGE_REC_USD, MOCK_PROV)) .thenReturn(expected); DispatchingSwapPaymentEventPricer test = new DispatchingSwapPaymentEventPricer( MOCK_NOTIONAL_EXG, mockCalledFn); assertThat(test.currencyExposure(SwapDummyData.FX_RESET_NOTIONAL_EXCHANGE_REC_USD, MOCK_PROV)).isEqualTo(expected); }
@Test public void test_currencyExposure_unknownType() { SwapPaymentEvent mockPaymentEvent = mock(SwapPaymentEvent.class); DispatchingSwapPaymentEventPricer test = DispatchingSwapPaymentEventPricer.DEFAULT; assertThatIllegalArgumentException() .isThrownBy(() -> test.currencyExposure(mockPaymentEvent, MOCK_PROV)); }