AmountService implements AmountRepository { @NonNull @Override public BigDecimal getAppliedCharges(@NonNull final String paymentTypeId, @Nullable final PayerCost payerCost) { if (payerCost == null) { return chargeRepository.getChargeAmount(paymentTypeId); } else { return payerCost.getTotalAmount() .subtract(getItemsAmount()) .add(getDiscountAmount()); } } 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 whenGetAppliedChargesAndNoCardChargesReturnOnlyChargesByPaymentMethod() { when(chargeRepository.getChargeAmount(PaymentTypes.CREDIT_CARD)).thenReturn(BigDecimal.TEN); assertEquals(BigDecimal.TEN, amountService.getAppliedCharges(PaymentTypes.CREDIT_CARD, null)); }
@Test public void whenGetAppliedChargesAndCardChargesReturnSumOfThem() { when(checkoutPreference.getTotalAmount()).thenReturn(BigDecimal.ONE); when(discountRepository.getCurrentConfiguration().getDiscount()).thenReturn(null); when(payerCost.getTotalAmount()).thenReturn(BigDecimal.TEN); assertEquals(new BigDecimal("9"), amountService.getAppliedCharges(PaymentTypes.CREDIT_CARD, payerCost)); }