CartItemImpl implements CartItem { public BigDecimal removeQuantity(final BigDecimal quantity) throws CartItemRequiresDeletion { if (MoneyUtils.isPositive(quantity)) { if (MoneyUtils.isFirstBiggerThanOrEqualToSecond(quantity, this.quantity)) { throw new CartItemRequiresDeletion(); } else { this.quantity = this.quantity.subtract(quantity); } } return getQty(); }  @Override String getProductSkuCode(); @Override String getProductName(); void setProductName(final String productName); @Override String getSupplierCode(); void setSupplierCode(final String supplierCode); @Override String getDeliveryGroup(); void setDeliveryGroup(final String deliveryGroup); @Override String getItemGroup(); void setItemGroup(final String itemGroup); @Override @JsonIgnore DeliveryBucket getDeliveryBucket(); @Override BigDecimal getQty(); void setQuantity(final BigDecimal quantity); BigDecimal addQuantity(final BigDecimal quantity); BigDecimal removeQuantity(final BigDecimal quantity); @Override BigDecimal getPrice(); void setPrice(final BigDecimal price); @Override BigDecimal getNetPrice(); void setNetPrice(final BigDecimal netPrice); @Override BigDecimal getGrossPrice(); void setGrossPrice(final BigDecimal grossPrice); @Override String getTaxCode(); void setTaxCode(final String taxCode); @Override BigDecimal getTaxRate(); void setTaxRate(final BigDecimal taxRate); @Override boolean isTaxExclusiveOfPrice(); void setTaxExclusiveOfPrice(final boolean taxExclusiveOfPrice); @Override BigDecimal getListPrice(); void setListPrice(final BigDecimal listPrice); @Override BigDecimal getSalePrice(); void setSalePrice(final BigDecimal salePrice); @Override boolean isNotSoldSeparately(); void setNotSoldSeparately(final boolean notSoldSeparately); @Override boolean isConfigurable(); void setConfigurable(final boolean configurable); @Override boolean isGift(); void setGift(final boolean gift); @Override boolean isFixedPrice(); void setFixedPrice(final boolean fixedPrice); @Override boolean isPromoApplied(); void setPromoApplied(final boolean promoApplied); @Override String getAppliedPromo(); void setAppliedPromo(final String appliedPromo); @Override String toString();  }
@Test(expected = CartItemRequiresDeletion.class) public void testRemoveQuantityWithCartItemRequiresDeletionException() throws CartItemRequiresDeletion { item.removeQuantity(BigDecimal.TEN); }
@Test public void testRemoveQuantity() throws CartItemRequiresDeletion { BigDecimal original = item.addQuantity(new BigDecimal(100)); BigDecimal newValue = item.removeQuantity(BigDecimal.TEN); assertFalse("must be of equal value to original when negative is removed", MoneyUtils.isFirstEqualToSecond(original, newValue)); assertTrue("must be of equal value to original when negative is removed", MoneyUtils.isFirstEqualToSecond(newValue, item.getQty())); assertTrue("must be of equal value to original when negative is removed", MoneyUtils.isFirstEqualToSecond(newValue, new BigDecimal(91))); }