Products extends Helper { public void remove(String productId) { int length; int index; if (cart != null) { ArrayList<Product> products = cart.getProductsList(); length = products.size(); index = -1; for (int i = 0; i < length; i++) { if (products.get(i).getProductId().equals(productId)) { index = i; break; } } if (index > -1) { cart.getProductsList().remove(index); } } else { ArrayList<BusinessObject> objects = new ArrayList<>(); objects.addAll(tracker.getBusinessObjects().values()); length = objects.size(); for (int i = 0; i < length; i++) { if (objects.get(i) instanceof Product && ((Product) objects.get(i)).getProductId().equals(productId)) { tracker.getBusinessObjects().remove(objects.get(i).getId()); break; } } } } Products(Tracker tracker);   Products(Cart cart); Product add(Product product); Product add(String productId); Product add(String productId, String category1); Product add(String productId, String category1, String category2); Product add(String productId, String category1, String category2, String category3); Product add(String productId, String category1, String category2, String category3, String category4); Product add(String productId, String category1, String category2, String category3, String category4, String category5); Product add(String productId, String category1, String category2, String category3, String category4, String category5, String category6); void remove(String productId); void removeAll(); void sendViews();  }
@Test public void removeTest() { Product p = new Product(tracker).setProductId("pdtID"); Product p2 = new Product(tracker).setProductId("pdtID2"); productsTracker.add(p); productsTracker.add(p2); productsCart.add(p); productsCart.add(p2); assertEquals(2, tracker.getBusinessObjects().size()); assertEquals(2, tracker.Cart().getProductsList().size()); productsTracker.remove("pdtID"); productsTracker.remove("test"); productsCart.remove("pdtID2"); assertEquals(1, tracker.getBusinessObjects().size()); assertEquals(1, tracker.Cart().getProductsList().size()); }