### Question:
DiscountingCmsLegPricer { public CurrencyAmount presentValue( ResolvedCmsLeg cmsLeg, RatesProvider ratesProvider) { return cmsLeg.getCmsPeriods() .stream() .map(cmsPeriod -> cmsPeriodPricer.presentValue(cmsPeriod, ratesProvider)) .reduce((c1, c2) -> c1.plus(c2)) .get(); } DiscountingCmsLegPricer(DiscountingCmsPeriodPricer cmsPeriodPricer); CurrencyAmount presentValue(
      ResolvedCmsLeg cmsLeg,
      RatesProvider ratesProvider); PointSensitivityBuilder presentValueSensitivity(
      ResolvedCmsLeg cmsLeg,
      RatesProvider ratesProvider); CurrencyAmount currentCash(
      ResolvedCmsLeg cmsLeg,
      RatesProvider ratesProvider);  }### Answer:
@Test public void test_presentValue() { CurrencyAmount computed = LEG_PRICER.presentValue(COUPON_LEG, RATES_PROVIDER); double expected = 0d; List<CmsPeriod> cms = COUPON_LEG.getCmsPeriods(); int size = cms.size(); for (int i = 0; i < size; ++i) { expected += PERIOD_PRICER.presentValue(cms.get(i), RATES_PROVIDER).getAmount(); } assertThat(computed.getCurrency()).isEqualTo(EUR); assertThat(computed.getAmount()).isCloseTo(expected, offset(TOLERANCE_PV)); }
@Test public void test_presentValue_afterPay() { CurrencyAmount computed = LEG_PRICER.presentValue(COUPON_LEG, RATES_PROVIDER_AFTER_PERIOD); double expected = 0d; List<CmsPeriod> cms = COUPON_LEG.getCmsPeriods(); int size = cms.size(); for (int i = 1; i < size; ++i) { expected += PERIOD_PRICER.presentValue( cms.get(i), RATES_PROVIDER_AFTER_PERIOD).getAmount(); } assertThat(computed.getCurrency()).isEqualTo(EUR); assertThat(computed.getAmount()).isCloseTo(expected, offset(TOLERANCE_PV)); }
@Test public void test_presentValue_ended() { CurrencyAmount computed = LEG_PRICER.presentValue(COUPON_LEG, RATES_PROVIDER_ENDED); assertThat(computed).isEqualTo(CurrencyAmount.zero(EUR)); }