RemoveCouponEventCommandImpl extends AbstractCartCommandImpl implements ShoppingCartCommand { @Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { final Object coupon = parameters.get(getCmdKey()); if (coupon instanceof String ) { final String couponCode = (String) coupon; if (StringUtils.isNotBlank(couponCode)) { if (shoppingCart.removeCoupon(couponCode)) { recalculate(shoppingCart); markDirty(shoppingCart); } } } } } RemoveCouponEventCommandImpl(final ShoppingCartCommandRegistry registry); @Override String getCmdKey(); @Override void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters);  }
@Test public void testExecute() { MutableShoppingCart shoppingCart = new ShoppingCartImpl(); shoppingCart.initialise(ctx().getBean("amountCalculationStrategy", AmountCalculationStrategy.class)); final ShoppingCartCommandFactory commands = ctx().getBean("shoppingCartCommandFactory", ShoppingCartCommandFactory.class); commands.execute(shoppingCart, (Map) singletonMap(ShoppingCartCommand.CMD_SETSHOP, 10)); commands.execute(shoppingCart, (Map) singletonMap(ShoppingCartCommand.CMD_CHANGECURRENCY, "EUR")); assertEquals(MoneyUtils.ZERO, shoppingCart.getTotal().getSubTotal()); final String couponCodeValid = "CMDTEST-REM001"; createCoupon(couponCodeValid, shoppingCart.getShoppingContext().getShopCode(), shoppingCart.getCurrencyCode()); Map<String, String> params = new HashMap<>(); params.put(ShoppingCartCommand.CMD_ADDTOCART, "CC_TEST1"); commands.execute(shoppingCart, (Map) params); assertEquals("19.99", shoppingCart.getTotal().getSubTotal().toPlainString()); params.remove(ShoppingCartCommand.CMD_ADDTOCART); params.put(ShoppingCartCommand.CMD_ADDCOUPON, couponCodeValid); commands.execute(shoppingCart, (Map) params); assertEquals(1, shoppingCart.getCoupons().size()); assertEquals(1, shoppingCart.getAppliedCoupons().size()); assertTrue(shoppingCart.getAppliedCoupons().contains(couponCodeValid)); assertTrue(shoppingCart.getTotal().getAppliedOrderPromo().contains("PROMO-" + couponCodeValid)); assertEquals("17.99", shoppingCart.getTotal().getSubTotal().toPlainString()); params.remove(ShoppingCartCommand.CMD_ADDCOUPON); params.put(ShoppingCartCommand.CMD_REMOVECOUPON, couponCodeValid); commands.execute(shoppingCart, (Map) params); assertTrue(shoppingCart.getCoupons().isEmpty()); assertTrue(shoppingCart.getAppliedCoupons().isEmpty()); assertEquals("19.99", shoppingCart.getTotal().getSubTotal().toPlainString()); assertNull(shoppingCart.getTotal().getAppliedOrderPromo()); }