Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "fix: updates build config and adjust tests" #459

Merged
merged 1 commit into from
Oct 27, 2024
Merged
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
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");
}
}
Loading