AmountService implements AmountRepository { @Override @NonNull public BigDecimal getAmountToPay(@NonNull final String paymentTypeId, @Nullable final PayerCost payerCost) { if (payerCost == null) { return getItemsPlusCharges(paymentTypeId) .subtract(getDiscountAmount()); } else { return payerCost.getTotalAmount(); } } AmountService(@NonNull final PaymentSettingRepository paymentSetting,
        @NonNull final ChargeRepository chargeRepository,
        @NonNull final DiscountRepository discountRepository); @Override @NonNull BigDecimal getAmountToPay(@NonNull final String paymentTypeId, @Nullable final PayerCost payerCost); @NonNull @Override BigDecimal getAmountToPay(@NonNull final String paymentTypeId,
        @NonNull final DiscountConfigurationModel discountModel); @Override @NonNull BigDecimal getItemsAmount(); @NonNull @Override BigDecimal getItemsPlusCharges(@NonNull final String paymentTypeId); @NonNull @Override BigDecimal getAppliedCharges(@NonNull final String paymentTypeId, @Nullable final PayerCost payerCost); @NonNull @Override BigDecimal getAmountWithoutDiscount(@NonNull final String paymentTypeId, @Nullable final PayerCost payerCost);  }
@Test public void whenHasDiscountAndNoChargesAmountThenGetAmountToPayIsAmountLessDiscount() { when(chargeRepository.getChargeAmount(PaymentTypes.CREDIT_CARD)).thenReturn(BigDecimal.ZERO); assertEquals(BigDecimal.TEN.subtract(BigDecimal.ONE), amountService.getAmountToPay(PaymentTypes.CREDIT_CARD, (PayerCost) null)); }
@Test public void whenHasNoDiscountAndNoChargesAmountThenGetAmountToPayIsJustAmount() { when(chargeRepository.getChargeAmount(PaymentTypes.CREDIT_CARD)).thenReturn(BigDecimal.ZERO); when(discountRepository.getCurrentConfiguration()).thenReturn(WITHOUT_DISCOUNT); assertEquals(BigDecimal.TEN, amountService.getAmountToPay(PaymentTypes.CREDIT_CARD, (PayerCost) null)); }
@Test public void whenHasNoDiscountAndHasChargesAmountThenGetAmountToPayIsAmountPlusChargesAmount() { when(chargeRepository.getChargeAmount(PaymentTypes.CREDIT_CARD)).thenReturn(BigDecimal.ONE); when(discountRepository.getCurrentConfiguration()).thenReturn(WITHOUT_DISCOUNT); assertEquals(BigDecimal.TEN.add(BigDecimal.ONE), amountService.getAmountToPay(PaymentTypes.CREDIT_CARD, (PayerCost) null)); }
@Test public void whenHasDiscountAndHasChargesAmountThenGetAmountToPayIsAmountLessDiscountAndPlusChargesAmount() { when(chargeRepository.getChargeAmount(PaymentTypes.CREDIT_CARD)).thenReturn(BigDecimal.ONE); assertEquals(BigDecimal.TEN, amountService.getAmountToPay(PaymentTypes.CREDIT_CARD, (PayerCost) null)); }
@Test public void whenGetAmountToPayChargesAndCardChargesReturnCardTotal() { when(payerCost.getTotalAmount()).thenReturn(BigDecimal.TEN); assertEquals(BigDecimal.TEN, amountService.getAmountToPay(PaymentTypes.CREDIT_CARD, payerCost)); }