@Test public void testGetOrderTotalAmountTaxZeroSale() throws Exception { final Total total = this.mockery.mock(Total.class, "total"); final CustomerOrder order = this.mockery.mock(CustomerOrder.class, "order"); final ShoppingCart cart = this.mockery.mock(ShoppingCart.class, "cart"); final CheckoutServiceFacadeImpl facade = new CheckoutServiceFacadeImpl(null, null, null, null, null, null, null, null) { @Override public Total getOrderTotal(final CustomerOrder customerOrder) { assertSame(customerOrder, order); return total; } @Override String determineTaxCode(final CustomerOrder customerOrder) { return "TAX"; } }; this.mockery.checking(new Expectations() {{ allowing(total).getTotalTax(); will(returnValue(Total.ZERO)); allowing(total).getTotalAmount(); will(returnValue(new BigDecimal("99.99"))); allowing(total).getListTotalAmount(); will(returnValue(new BigDecimal("129.99"))); allowing(order).getCurrency(); will(returnValue("EUR")); }}); final PriceModel model = facade.getOrderTotalAmount(order, cart); assertNotNull(model); assertEquals(CheckoutServiceFacadeImpl.ORDER_TOTAL_REF, model.getRef()); assertEquals("EUR", model.getCurrency()); assertEquals("1", model.getQuantity().toPlainString()); assertEquals("129.99", model.getRegularPrice().toPlainString()); assertEquals("99.99", model.getSalePrice().toPlainString()); assertFalse(model.isTaxInfoEnabled()); assertFalse(model.isTaxInfoUseNet()); assertFalse(model.isTaxInfoShowAmount()); assertNull(model.getPriceTaxCode()); assertNull(model.getPriceTaxRate()); assertFalse(model.isPriceTaxExclusive()); assertNull(model.getPriceTax()); mockery.assertIsSatisfied(); }
@Override public PriceModel getOrderTotalAmount(final CustomerOrder customerOrder, final ShoppingCart cart) { final Total grandTotal = getOrderTotal(customerOrder); final boolean hasTax = MoneyUtils.isPositive(grandTotal.getTotalTax()); final boolean showTax = hasTax; final boolean showTaxAmount = showTax && cart.getShoppingContext().isTaxInfoShowAmount(); final boolean hasDiscounts = MoneyUtils.isFirstBiggerThanSecond(grandTotal.getListTotalAmount(), grandTotal.getTotalAmount()); if (showTax) { final String firstTaxCode = determineTaxCode(customerOrder); final BigDecimal netAmount = grandTotal.getTotalAmount().subtract(grandTotal.getTotalTax()); final BigDecimal taxPercent = grandTotal.getTotalTax().divide(netAmount, Constants.TAX_SCALE, BigDecimal.ROUND_FLOOR); final BigDecimal taxRate = taxPercent.multiply(MoneyUtils.HUNDRED).setScale(Constants.MONEY_SCALE, BigDecimal.ROUND_HALF_UP); return new PriceModelImpl( ORDER_TOTAL_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, hasDiscounts ? grandTotal.getListTotalAmount() : grandTotal.getTotalAmount(), hasDiscounts ? grandTotal.getTotalAmount() : null, showTax, false, showTaxAmount, firstTaxCode, taxRate, false, grandTotal.getTotalTax() ); } if (hasDiscounts) { return new PriceModelImpl( ORDER_TOTAL_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, grandTotal.getListTotalAmount(), grandTotal.getTotalAmount() ); } return new PriceModelImpl( ORDER_TOTAL_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, grandTotal.getTotalAmount(), null ); }
CheckoutServiceFacadeImpl implements CheckoutServiceFacade { @Override public PriceModel getOrderTotalAmount(final CustomerOrder customerOrder, final ShoppingCart cart) { final Total grandTotal = getOrderTotal(customerOrder); final boolean hasTax = MoneyUtils.isPositive(grandTotal.getTotalTax()); final boolean showTax = hasTax; final boolean showTaxAmount = showTax && cart.getShoppingContext().isTaxInfoShowAmount(); final boolean hasDiscounts = MoneyUtils.isFirstBiggerThanSecond(grandTotal.getListTotalAmount(), grandTotal.getTotalAmount()); if (showTax) { final String firstTaxCode = determineTaxCode(customerOrder); final BigDecimal netAmount = grandTotal.getTotalAmount().subtract(grandTotal.getTotalTax()); final BigDecimal taxPercent = grandTotal.getTotalTax().divide(netAmount, Constants.TAX_SCALE, BigDecimal.ROUND_FLOOR); final BigDecimal taxRate = taxPercent.multiply(MoneyUtils.HUNDRED).setScale(Constants.MONEY_SCALE, BigDecimal.ROUND_HALF_UP); return new PriceModelImpl( ORDER_TOTAL_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, hasDiscounts ? grandTotal.getListTotalAmount() : grandTotal.getTotalAmount(), hasDiscounts ? grandTotal.getTotalAmount() : null, showTax, false, showTaxAmount, firstTaxCode, taxRate, false, grandTotal.getTotalTax() ); } if (hasDiscounts) { return new PriceModelImpl( ORDER_TOTAL_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, grandTotal.getListTotalAmount(), grandTotal.getTotalAmount() ); } return new PriceModelImpl( ORDER_TOTAL_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, grandTotal.getTotalAmount(), null ); } }
CheckoutServiceFacadeImpl implements CheckoutServiceFacade { @Override public PriceModel getOrderTotalAmount(final CustomerOrder customerOrder, final ShoppingCart cart) { final Total grandTotal = getOrderTotal(customerOrder); final boolean hasTax = MoneyUtils.isPositive(grandTotal.getTotalTax()); final boolean showTax = hasTax; final boolean showTaxAmount = showTax && cart.getShoppingContext().isTaxInfoShowAmount(); final boolean hasDiscounts = MoneyUtils.isFirstBiggerThanSecond(grandTotal.getListTotalAmount(), grandTotal.getTotalAmount()); if (showTax) { final String firstTaxCode = determineTaxCode(customerOrder); final BigDecimal netAmount = grandTotal.getTotalAmount().subtract(grandTotal.getTotalTax()); final BigDecimal taxPercent = grandTotal.getTotalTax().divide(netAmount, Constants.TAX_SCALE, BigDecimal.ROUND_FLOOR); final BigDecimal taxRate = taxPercent.multiply(MoneyUtils.HUNDRED).setScale(Constants.MONEY_SCALE, BigDecimal.ROUND_HALF_UP); return new PriceModelImpl( ORDER_TOTAL_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, hasDiscounts ? grandTotal.getListTotalAmount() : grandTotal.getTotalAmount(), hasDiscounts ? grandTotal.getTotalAmount() : null, showTax, false, showTaxAmount, firstTaxCode, taxRate, false, grandTotal.getTotalTax() ); } if (hasDiscounts) { return new PriceModelImpl( ORDER_TOTAL_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, grandTotal.getListTotalAmount(), grandTotal.getTotalAmount() ); } return new PriceModelImpl( ORDER_TOTAL_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, grandTotal.getTotalAmount(), null ); } CheckoutServiceFacadeImpl(final CustomerOrderService customerOrderService,
                                     final AmountCalculationStrategy amountCalculationStrategy,
                                     final DeliveryTimeEstimationVisitor deliveryTimeEstimationVisitor,
                                     final CustomerOrderPaymentService customerOrderPaymentService,
                                     final CarrierSlaService carrierSlaService,
                                     final PaymentProcessorFactory paymentProcessorFactory,
                                     final PaymentModulesManager paymentModulesManager,
                                     final ReportGenerator reportGenerator); }
CheckoutServiceFacadeImpl implements CheckoutServiceFacade { @Override public PriceModel getOrderTotalAmount(final CustomerOrder customerOrder, final ShoppingCart cart) { final Total grandTotal = getOrderTotal(customerOrder); final boolean hasTax = MoneyUtils.isPositive(grandTotal.getTotalTax()); final boolean showTax = hasTax; final boolean showTaxAmount = showTax && cart.getShoppingContext().isTaxInfoShowAmount(); final boolean hasDiscounts = MoneyUtils.isFirstBiggerThanSecond(grandTotal.getListTotalAmount(), grandTotal.getTotalAmount()); if (showTax) { final String firstTaxCode = determineTaxCode(customerOrder); final BigDecimal netAmount = grandTotal.getTotalAmount().subtract(grandTotal.getTotalTax()); final BigDecimal taxPercent = grandTotal.getTotalTax().divide(netAmount, Constants.TAX_SCALE, BigDecimal.ROUND_FLOOR); final BigDecimal taxRate = taxPercent.multiply(MoneyUtils.HUNDRED).setScale(Constants.MONEY_SCALE, BigDecimal.ROUND_HALF_UP); return new PriceModelImpl( ORDER_TOTAL_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, hasDiscounts ? grandTotal.getListTotalAmount() : grandTotal.getTotalAmount(), hasDiscounts ? grandTotal.getTotalAmount() : null, showTax, false, showTaxAmount, firstTaxCode, taxRate, false, grandTotal.getTotalTax() ); } if (hasDiscounts) { return new PriceModelImpl( ORDER_TOTAL_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, grandTotal.getListTotalAmount(), grandTotal.getTotalAmount() ); } return new PriceModelImpl( ORDER_TOTAL_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, grandTotal.getTotalAmount(), null ); } CheckoutServiceFacadeImpl(final CustomerOrderService customerOrderService,
                                     final AmountCalculationStrategy amountCalculationStrategy,
                                     final DeliveryTimeEstimationVisitor deliveryTimeEstimationVisitor,
                                     final CustomerOrderPaymentService customerOrderPaymentService,
                                     final CarrierSlaService carrierSlaService,
                                     final PaymentProcessorFactory paymentProcessorFactory,
                                     final PaymentModulesManager paymentModulesManager,
                                     final ReportGenerator reportGenerator); @Override CustomerOrder findByReference(final String reference); @Override CustomerOrder findByGuid(final String shoppingCartGuid); @Override Total getOrderTotal(final CustomerOrder customerOrder); @Override PriceModel getOrderTotalSub(final CustomerOrder customerOrder, final ShoppingCart cart); @Override PriceModel getOrderTotalAmount(final CustomerOrder customerOrder, final ShoppingCart cart); @Override Total getOrderDeliveryTotal(final CustomerOrder customerOrder, final CustomerOrderDelivery delivery); @Override PriceModel getOrderDeliveryTotalSub(final CustomerOrder customerOrder, final CustomerOrderDelivery delivery, final ShoppingCart cart); @Override PriceModel getOrderDeliveryTotalShipping(final CustomerOrder customerOrder, final CustomerOrderDelivery delivery, final ShoppingCart cart); @Override List<CustomerOrderPayment> findPaymentRecordsByOrderNumber(final String orderNumber); @Override Payment createPaymentToAuthorize(final CustomerOrder order); @Override PaymentGateway getOrderPaymentGateway(final CustomerOrder order); @Override List<Pair<PaymentGatewayDescriptor, String>> getPaymentGatewaysDescriptors(final Shop shop, final ShoppingCart cart); @Override boolean isOrderPaymentSuccessful(final CustomerOrder customerOrder); @Override Set<String> getOrderPromoCodes(final CustomerOrder customerOrder); @Override Set<String> getOrderShippingPromoCodes(final CustomerOrderDelivery orderDelivery); @Override Set<String> getOrderItemPromoCodes(final CartItem orderDeliveryDet); @Override CartValidityModel validateCart(final ShoppingCart shoppingCart); @Override CustomerOrder createFromCart(final ShoppingCart shoppingCart); @Override void estimateDeliveryTimeForOnlinePaymentOrder(final CustomerOrder customerOrder); @Override Map<String, Boolean> isMultipleDeliveryAllowedForCart(final ShoppingCart shoppingCart); @Override CustomerOrder update(final CustomerOrder customerOrder); @Override void printOrderByReference(final String reference, final OutputStream outputStream); }
CheckoutServiceFacadeImpl implements CheckoutServiceFacade { @Override public PriceModel getOrderTotalAmount(final CustomerOrder customerOrder, final ShoppingCart cart) { final Total grandTotal = getOrderTotal(customerOrder); final boolean hasTax = MoneyUtils.isPositive(grandTotal.getTotalTax()); final boolean showTax = hasTax; final boolean showTaxAmount = showTax && cart.getShoppingContext().isTaxInfoShowAmount(); final boolean hasDiscounts = MoneyUtils.isFirstBiggerThanSecond(grandTotal.getListTotalAmount(), grandTotal.getTotalAmount()); if (showTax) { final String firstTaxCode = determineTaxCode(customerOrder); final BigDecimal netAmount = grandTotal.getTotalAmount().subtract(grandTotal.getTotalTax()); final BigDecimal taxPercent = grandTotal.getTotalTax().divide(netAmount, Constants.TAX_SCALE, BigDecimal.ROUND_FLOOR); final BigDecimal taxRate = taxPercent.multiply(MoneyUtils.HUNDRED).setScale(Constants.MONEY_SCALE, BigDecimal.ROUND_HALF_UP); return new PriceModelImpl( ORDER_TOTAL_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, hasDiscounts ? grandTotal.getListTotalAmount() : grandTotal.getTotalAmount(), hasDiscounts ? grandTotal.getTotalAmount() : null, showTax, false, showTaxAmount, firstTaxCode, taxRate, false, grandTotal.getTotalTax() ); } if (hasDiscounts) { return new PriceModelImpl( ORDER_TOTAL_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, grandTotal.getListTotalAmount(), grandTotal.getTotalAmount() ); } return new PriceModelImpl( ORDER_TOTAL_REF, customerOrder.getCurrency(), BigDecimal.ONE, false, false, grandTotal.getTotalAmount(), null ); } CheckoutServiceFacadeImpl(final CustomerOrderService customerOrderService,
                                     final AmountCalculationStrategy amountCalculationStrategy,
                                     final DeliveryTimeEstimationVisitor deliveryTimeEstimationVisitor,
                                     final CustomerOrderPaymentService customerOrderPaymentService,
                                     final CarrierSlaService carrierSlaService,
                                     final PaymentProcessorFactory paymentProcessorFactory,
                                     final PaymentModulesManager paymentModulesManager,
                                     final ReportGenerator reportGenerator); @Override CustomerOrder findByReference(final String reference); @Override CustomerOrder findByGuid(final String shoppingCartGuid); @Override Total getOrderTotal(final CustomerOrder customerOrder); @Override PriceModel getOrderTotalSub(final CustomerOrder customerOrder, final ShoppingCart cart); @Override PriceModel getOrderTotalAmount(final CustomerOrder customerOrder, final ShoppingCart cart); @Override Total getOrderDeliveryTotal(final CustomerOrder customerOrder, final CustomerOrderDelivery delivery); @Override PriceModel getOrderDeliveryTotalSub(final CustomerOrder customerOrder, final CustomerOrderDelivery delivery, final ShoppingCart cart); @Override PriceModel getOrderDeliveryTotalShipping(final CustomerOrder customerOrder, final CustomerOrderDelivery delivery, final ShoppingCart cart); @Override List<CustomerOrderPayment> findPaymentRecordsByOrderNumber(final String orderNumber); @Override Payment createPaymentToAuthorize(final CustomerOrder order); @Override PaymentGateway getOrderPaymentGateway(final CustomerOrder order); @Override List<Pair<PaymentGatewayDescriptor, String>> getPaymentGatewaysDescriptors(final Shop shop, final ShoppingCart cart); @Override boolean isOrderPaymentSuccessful(final CustomerOrder customerOrder); @Override Set<String> getOrderPromoCodes(final CustomerOrder customerOrder); @Override Set<String> getOrderShippingPromoCodes(final CustomerOrderDelivery orderDelivery); @Override Set<String> getOrderItemPromoCodes(final CartItem orderDeliveryDet); @Override CartValidityModel validateCart(final ShoppingCart shoppingCart); @Override CustomerOrder createFromCart(final ShoppingCart shoppingCart); @Override void estimateDeliveryTimeForOnlinePaymentOrder(final CustomerOrder customerOrder); @Override Map<String, Boolean> isMultipleDeliveryAllowedForCart(final ShoppingCart shoppingCart); @Override CustomerOrder update(final CustomerOrder customerOrder); @Override void printOrderByReference(final String reference, final OutputStream outputStream);  }