### Question:
OnlineShopping { public void switchStore(Store storeToSwitchTo) { Cart cart = (Cart) session.get("CART"); DeliveryInformation deliveryInformation = (DeliveryInformation) session.get("DELIVERY_INFO"); if (storeToSwitchTo == null) { if (cart != null) { for (Item item : cart.getItems()) { if ("EVENT".equals(item.getType())) { cart.markAsUnavailable(item); } } } if (deliveryInformation != null) { deliveryInformation.setType("SHIPPING"); deliveryInformation.setPickupLocation(null); } } else { if (cart != null) { ArrayList<Item> newItems = new ArrayList<>(); long weight = 0; for (Item item : cart.getItems()) { if ("EVENT".equals(item.getType())) { if (storeToSwitchTo.hasItem(item)) { cart.markAsUnavailable(item); newItems.add(storeToSwitchTo.getItem(item.getName())); } else { cart.markAsUnavailable(item); } } else if (!storeToSwitchTo.hasItem(item)) { cart.markAsUnavailable(item); } weight += item.getWeight(); } for (Item item: cart.getUnavailableItems()) { weight -= item.getWeight(); } Store currentStore = (Store) session.get("STORE"); if (deliveryInformation != null && deliveryInformation.getType() != null && "HOME_DELIVERY".equals(deliveryInformation.getType()) && deliveryInformation.getDeliveryAddress() != null) { if (!((LocationService) session.get("LOCATION_SERVICE")).isWithinDeliveryRange(storeToSwitchTo, deliveryInformation.getDeliveryAddress())) { deliveryInformation.setType("PICKUP"); deliveryInformation.setPickupLocation(currentStore); } else { deliveryInformation.setTotalWeight(weight); deliveryInformation.setPickupLocation(storeToSwitchTo); } } else { if (deliveryInformation != null && deliveryInformation.getDeliveryAddress() != null) { if (((LocationService) session.get("LOCATION_SERVICE")).isWithinDeliveryRange(storeToSwitchTo, deliveryInformation.getDeliveryAddress())) { deliveryInformation.setType("HOME_DELIVERY"); deliveryInformation.setTotalWeight(weight); deliveryInformation.setPickupLocation(storeToSwitchTo); } } } for (Item item : newItems) { cart.addItem(item); } } } session.put("STORE", storeToSwitchTo); session.saveAll(); } OnlineShopping(Session session); void switchStore(Store storeToSwitchTo); @Override String toString();  }### Answer:
@Test public void switchStore() throws Exception { DeliveryInformation deliveryInfo = new DeliveryInformation("HOME_DELIVERY", nordstan, 60); deliveryInfo.setDeliveryAddress("NEARBY"); Cart cart = new Cart(); cart.addItem(cherryBloom); cart.addItem(blusherBrush); cart.addItem(masterclass); cart.addItem(makeoverNordstan); Session session = new Session(); session.put("STORE", nordstan); session.put("DELIVERY_INFO", deliveryInfo); session.put("CART", cart); OnlineShopping shopping = new OnlineShopping(session); }