SetOrderMessageCommandImpl extends AbstractCartCommandImpl implements ShoppingCartCommand { @Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { final String value = (String) parameters.get(getCmdKey()); if ((value != null && !value.equals(shoppingCart.getOrderInfo().getOrderMessage())) || (value == null && shoppingCart.getOrderInfo().getOrderMessage() != null)) { shoppingCart.getOrderInfo().setOrderMessage(value); markDirty(shoppingCart); } } } SetOrderMessageCommandImpl(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); assertNull(shoppingCart.getOrderInfo().getPaymentGatewayLabel()); Map params = new HashMap(); params.put(SetPaymentGatewayLabelCommandImpl.CMD_SETORDERMSG, "message"); commands.execute(shoppingCart, params); assertEquals("message", shoppingCart.getOrderInfo().getOrderMessage()); params.put(SetPaymentGatewayLabelCommandImpl.CMD_SETORDERMSG, "qwerty"); commands.execute(shoppingCart, params); assertEquals("qwerty", shoppingCart.getOrderInfo().getOrderMessage()); params.put(SetPaymentGatewayLabelCommandImpl.CMD_SETORDERMSG, null); commands.execute(shoppingCart, params); assertNull(shoppingCart.getOrderInfo().getOrderMessage()); }