Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert changes to this file.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public class Lesson14 {

public static void main(String[] args) {

System.out.println("Hello World");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ public void addProduct(String productId, String name) {
products.put(productId, new Product(productId, name));
}

public String placeOrder(String productId, int quantity) {
public String placeOrder(String productId, int quantity) throws ProductNotFoundException {
Product product = products.get(productId);

if (product == null) {
// This will throw a custom exception when order is not found, or null.
throw new ProductNotFoundException("Product with ID " + productId + " not found");
}

String orderId = UUID.randomUUID().toString();
orders.put(orderId, new Order(orderId, product, quantity));
return orderId;
Expand All @@ -28,8 +34,14 @@ public void cancelOrder(String orderId) {
orders.remove(orderId);
}

public String checkOrderStatus(String orderId) {
public String checkOrderStatus(String orderId) throws OrderNotFoundException {
Order order = orders.get(orderId);

if (order == null) {
// This will throw a custom exception when order is not found, or null.
throw new OrderNotFoundException("Order with ID " + orderId + " not found");
}

return "Order ID: "
+ orderId
+ ", Product: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@

package com.codedifferently.lesson14.ecommerce;

class OrderNotFoundException {}
public class OrderNotFoundException extends Exception {
public OrderNotFoundException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@

package com.codedifferently.lesson14.ecommerce;

class ProductNotFoundException {}
public class ProductNotFoundException extends Exception {
public ProductNotFoundException(String message) {
super(message);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't have changed this file, please revert.

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void testCancelOrder() throws Exception {
}

@Test
void testCheckOrderStatus_orderDoesNotExist() {
void testCheckOrderStatus_orderDoesNotExist() throws Exception {
// Act
assertThatThrownBy(() -> ecommerceSystem.checkOrderStatus("1"))
.isInstanceOf(OrderNotFoundException.class)
Expand Down