Skip to content

Commit 3f6990e

Browse files
committed
feat: Add's Nana's lesson 13 Homework ((unfinished))
1 parent 8b9f40a commit 3f6990e

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

lesson_14/exceptions/exceptions_app/src/test/java/com/codedifferently/lesson14/ecommerce/EcommerceSystemTest.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import static org.assertj.core.api.Assertions.assertThat;
44
import static org.assertj.core.api.Assertions.assertThatThrownBy;
55

6+
import java.util.UUID;
7+
68
import org.junit.jupiter.api.BeforeEach;
79
import org.junit.jupiter.api.Test;
810

@@ -15,16 +17,31 @@ void setUp() {
1517
ecommerceSystem = new EcommerceSystem();
1618
}
1719

18-
@Test
19-
void testAddProduct() {
20-
// Act
21-
ecommerceSystem.addProduct("1", "Laptop");
20+
public void AddProduct(String productID, String name) {
21+
products.put(productID, new Product(productID, name));
22+
}
23+
public String placeOrder(String produtID, int quantity) {
24+
Product product = products.get(productId);
25+
if (product == null) {
26+
throw new ProductNotFoundException("Product with ID " + productID + "not found");
27+
}
28+
String orderID = UUID.randomUUID().toString();
29+
orders.put(orderID, new Order(orderID, product, quantity));
30+
return orderID;
2231
}
2332

2433
@Test
2534
void testPlaceOrder() throws Exception {
2635
// Arrange
2736
ecommerceSystem.addProduct("1", "Laptop");
37+
public class UnsupportedOperationException extends Exception {
38+
public UnsupportedOperationException(String message) {
39+
super(message);
40+
}
41+
}
42+
43+
}
44+
}
2845

2946
// Act
3047
String orderId = ecommerceSystem.placeOrder("1", 1);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.codedifferently.lesson14.ecommerce;
2+
3+
public class OrderNotFoundException {
4+
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.codedifferently.lesson14.ecommerce;
2+
3+
public class ProductNotFoundException {
4+
5+
}

0 commit comments

Comments
 (0)