Skip to content

Commit

Permalink
Revert "fix: updates build config and adjust tests (#458)"
Browse files Browse the repository at this point in the history
This reverts commit d3fa849.
  • Loading branch information
anthonydmays authored Oct 27, 2024
1 parent d3fa849 commit 7fa8ece
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lesson_13/maps_java/maps_app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {

application {
// Define the main class for the application.
mainClass.set("com.codedifferently.lesson13.Lesson13")
mainClass.set("com.codedifferently.lesson12.Lesson12")
}

tasks.named<Test>("test") {
Expand Down
2 changes: 1 addition & 1 deletion lesson_14/exceptions/exceptions_app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {

application {
// Define the main class for the application.
mainClass.set("com.codedifferently.lesson14.Lesson14")
mainClass.set("com.codedifferently.lesson12.Lesson12")
}

tasks.named<Test>("test") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.UUID;

public class EcommerceSystem {

private Map<String, Product> products;
private Map<String, Order> orders;

Expand All @@ -18,11 +17,8 @@ public void addProduct(String productId, String name) {
products.put(productId, new Product(productId, name));
}

public String placeOrder(String productId, int quantity) throws ProductNotFoundException {
public String placeOrder(String productId, int quantity) {
Product product = products.get(productId);
if (product == 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 @@ -32,11 +28,8 @@ public void cancelOrder(String orderId) {
orders.remove(orderId);
}

public String checkOrderStatus(String orderId) throws OrderNotFoundException {
public String checkOrderStatus(String orderId) {
Order order = orders.get(orderId);
if (order == 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 @@ -2,11 +2,7 @@
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.codedifferently.lesson14.ecommerce;

class ProductNotFoundException extends RuntimeException {
package com.codedifferently.lesson14.ecommerce;

ProductNotFoundException(String message) {
super(message);
}
}
class ProductNotFoundException {}
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ void testPlaceOrder_productDoesNotExist() throws Exception {
assertThatThrownBy(() -> ecommerceSystem.placeOrder("1", 1))
.isInstanceOf(ProductNotFoundException.class)
.hasMessage("Product with ID 1 not found");

// Act
assertThatThrownBy(() -> ecommerceSystem.placeOrder("34", 1))
.isInstanceOf(ProductNotFoundException.class)
.hasMessage("Product with ID 34 not found");
}

@Test
Expand All @@ -63,23 +58,18 @@ void testCheckOrderStatus_orderDoesNotExist() {
assertThatThrownBy(() -> ecommerceSystem.checkOrderStatus("1"))
.isInstanceOf(OrderNotFoundException.class)
.hasMessage("Order with ID 1 not found");

// Act
assertThatThrownBy(() -> ecommerceSystem.checkOrderStatus("33"))
.isInstanceOf(OrderNotFoundException.class)
.hasMessage("Order with ID 33 not found");
}

@Test
void testCheckOrderStatus_orderCancelled() throws Exception {
// Arrange
ecommerceSystem.addProduct("58", "Laptop");
String orderId = ecommerceSystem.placeOrder("58", 1);
ecommerceSystem.addProduct("1", "Laptop");
String orderId = ecommerceSystem.placeOrder("1", 1);
ecommerceSystem.cancelOrder(orderId);

// Act
assertThatThrownBy(() -> ecommerceSystem.checkOrderStatus("58"))
assertThatThrownBy(() -> ecommerceSystem.checkOrderStatus("1"))
.isInstanceOf(OrderNotFoundException.class)
.hasMessage("Order with ID 58 not found");
.hasMessage("Order with ID 1 not found");
}
}

0 comments on commit 7fa8ece

Please sign in to comment.