@Test void cantOrderForNonExistentCustomer() { int customerId = 666; var quantities = Map.of(2, 1); assertThrows(IllegalArgumentException.class, () -> warehouse.addOrder(customerId, quantities)); }
public void addOrder(int customerId, Map<Integer, Integer> quantities) throws WarehouseException { if (quantities.isEmpty()) { throw new IllegalArgumentException("There has to items in the order, it cannot be empty."); } Customer customer = customerDao.getCustomer(customerId); if (customer == null) { throw new IllegalArgumentException("Unknown customer ID: " + customerId); } Map<Product, Integer> mappedQuantities = new HashMap<>(); for (var entry : quantities.entrySet()) { Product product = productDao.getProduct(entry.getKey()); if (product == null) { throw new IllegalArgumentException("Unknown product ID: " + entry.getKey()); } int quantity = entry.getValue(); if (quantity < 1) { throw new IllegalArgumentException("Ordered quantity must be greater than 0."); } mappedQuantities.put(product, quantity); } inventoryDao.updateStock(mappedQuantities); Order order = new Order(customer, mappedQuantities); orderDao.addOrder(order); }
Warehouse { public void addOrder(int customerId, Map<Integer, Integer> quantities) throws WarehouseException { if (quantities.isEmpty()) { throw new IllegalArgumentException("There has to items in the order, it cannot be empty."); } Customer customer = customerDao.getCustomer(customerId); if (customer == null) { throw new IllegalArgumentException("Unknown customer ID: " + customerId); } Map<Product, Integer> mappedQuantities = new HashMap<>(); for (var entry : quantities.entrySet()) { Product product = productDao.getProduct(entry.getKey()); if (product == null) { throw new IllegalArgumentException("Unknown product ID: " + entry.getKey()); } int quantity = entry.getValue(); if (quantity < 1) { throw new IllegalArgumentException("Ordered quantity must be greater than 0."); } mappedQuantities.put(product, quantity); } inventoryDao.updateStock(mappedQuantities); Order order = new Order(customer, mappedQuantities); orderDao.addOrder(order); } }
Warehouse { public void addOrder(int customerId, Map<Integer, Integer> quantities) throws WarehouseException { if (quantities.isEmpty()) { throw new IllegalArgumentException("There has to items in the order, it cannot be empty."); } Customer customer = customerDao.getCustomer(customerId); if (customer == null) { throw new IllegalArgumentException("Unknown customer ID: " + customerId); } Map<Product, Integer> mappedQuantities = new HashMap<>(); for (var entry : quantities.entrySet()) { Product product = productDao.getProduct(entry.getKey()); if (product == null) { throw new IllegalArgumentException("Unknown product ID: " + entry.getKey()); } int quantity = entry.getValue(); if (quantity < 1) { throw new IllegalArgumentException("Ordered quantity must be greater than 0."); } mappedQuantities.put(product, quantity); } inventoryDao.updateStock(mappedQuantities); Order order = new Order(customer, mappedQuantities); orderDao.addOrder(order); } Warehouse(
        ProductDao productDao,
        CustomerDao customerDao,
        InventoryDao inventoryDao,
        OrderDao orderDao,
        ReportGeneration reportGeneration,
        ExternalCustomerService externalCustomerService); }
Warehouse { public void addOrder(int customerId, Map<Integer, Integer> quantities) throws WarehouseException { if (quantities.isEmpty()) { throw new IllegalArgumentException("There has to items in the order, it cannot be empty."); } Customer customer = customerDao.getCustomer(customerId); if (customer == null) { throw new IllegalArgumentException("Unknown customer ID: " + customerId); } Map<Product, Integer> mappedQuantities = new HashMap<>(); for (var entry : quantities.entrySet()) { Product product = productDao.getProduct(entry.getKey()); if (product == null) { throw new IllegalArgumentException("Unknown product ID: " + entry.getKey()); } int quantity = entry.getValue(); if (quantity < 1) { throw new IllegalArgumentException("Ordered quantity must be greater than 0."); } mappedQuantities.put(product, quantity); } inventoryDao.updateStock(mappedQuantities); Order order = new Order(customer, mappedQuantities); orderDao.addOrder(order); } Warehouse(
        ProductDao productDao,
        CustomerDao customerDao,
        InventoryDao inventoryDao,
        OrderDao orderDao,
        ReportGeneration reportGeneration,
        ExternalCustomerService externalCustomerService); Collection<Product> getProducts(); Collection<Customer> getCustomers(); Collection<Order> getOrders(); void addProduct(String name, int price); void addOrder(int customerId, Map<Integer, Integer> quantities); Report generateReport(Report.Type type); }
Warehouse { public void addOrder(int customerId, Map<Integer, Integer> quantities) throws WarehouseException { if (quantities.isEmpty()) { throw new IllegalArgumentException("There has to items in the order, it cannot be empty."); } Customer customer = customerDao.getCustomer(customerId); if (customer == null) { throw new IllegalArgumentException("Unknown customer ID: " + customerId); } Map<Product, Integer> mappedQuantities = new HashMap<>(); for (var entry : quantities.entrySet()) { Product product = productDao.getProduct(entry.getKey()); if (product == null) { throw new IllegalArgumentException("Unknown product ID: " + entry.getKey()); } int quantity = entry.getValue(); if (quantity < 1) { throw new IllegalArgumentException("Ordered quantity must be greater than 0."); } mappedQuantities.put(product, quantity); } inventoryDao.updateStock(mappedQuantities); Order order = new Order(customer, mappedQuantities); orderDao.addOrder(order); } Warehouse(
        ProductDao productDao,
        CustomerDao customerDao,
        InventoryDao inventoryDao,
        OrderDao orderDao,
        ReportGeneration reportGeneration,
        ExternalCustomerService externalCustomerService); Collection<Product> getProducts(); Collection<Customer> getCustomers(); Collection<Order> getOrders(); void addProduct(String name, int price); void addOrder(int customerId, Map<Integer, Integer> quantities); Report generateReport(Report.Type type);  }