diff --git a/Shop/src/de/th_mannheim/informatik/main/java/shop/backend/Cart.java b/Shop/src/de/th_mannheim/informatik/main/java/shop/backend/Cart.java index 22ae69d..6145fbc 100644 --- a/Shop/src/de/th_mannheim/informatik/main/java/shop/backend/Cart.java +++ b/Shop/src/de/th_mannheim/informatik/main/java/shop/backend/Cart.java @@ -23,8 +23,9 @@ public void addProduct(Product prod, int quantity){ pos.setQuantity(pos.getQuantity() + quantity); //Damit erhöhe ich quantity break; } - positions.add(new CartPosition(prod, quantity)); + } + positions.add(new CartPosition(prod, quantity)); } public void updateProductQuantity(int prodID,int quantity) { diff --git a/Shop/src/de/th_mannheim/informatik/main/java/shop/backend/Order.java b/Shop/src/de/th_mannheim/informatik/main/java/shop/backend/Order.java index 22ef133..073260b 100644 --- a/Shop/src/de/th_mannheim/informatik/main/java/shop/backend/Order.java +++ b/Shop/src/de/th_mannheim/informatik/main/java/shop/backend/Order.java @@ -13,6 +13,9 @@ public class Order { private double totalBrutto; private double shippingCost; private double finalTotal; + //KI + private double mwstAmount7; + private double mwstAmount19; public Order(String customerName, String address, List positions) { @@ -39,7 +42,7 @@ public class Order { weight += pos.getProductWeight(); } - //KI Ansatz + //Denk anstoss if (weight <= 0.1) { shippingCost = 3.95; } else if (weight <= 1.0) { diff --git a/Shop/src/de/th_mannheim/informatik/main/java/shop/frontend/ShopTUI.java b/Shop/src/de/th_mannheim/informatik/main/java/shop/frontend/ShopTUI.java index 8e31a72..3554b1e 100644 --- a/Shop/src/de/th_mannheim/informatik/main/java/shop/frontend/ShopTUI.java +++ b/Shop/src/de/th_mannheim/informatik/main/java/shop/frontend/ShopTUI.java @@ -8,11 +8,12 @@ import shop.backend.Product; import java.io.FileNotFoundException; import java.util.ArrayList; +import java.util.Scanner; public class ShopTUI { private static OnlineShop onlineShop; private static Cart cart; - + private static Scanner scanner = new Scanner(System.in); public static void main(String[] args) throws FileNotFoundException { IO.println("\n+--------------------------------------+"); IO.println("| WELCOME TO THE ONLINE SHOP |"); @@ -49,7 +50,7 @@ public class ShopTUI { int choice; do { menu(); - choice = Integer.parseInt(IO.readln()); + choice = scanner.nextInt(); switch (choice) { case 1: showProducts(); diff --git a/Shop/src/de/th_mannheim/informatik/test/java/shop/backend/CartTest.java b/Shop/src/de/th_mannheim/informatik/test/java/shop/backend/CartTest.java index e605ad5..d923cef 100644 --- a/Shop/src/de/th_mannheim/informatik/test/java/shop/backend/CartTest.java +++ b/Shop/src/de/th_mannheim/informatik/test/java/shop/backend/CartTest.java @@ -1,5 +1,26 @@ package shop.backend; -class CartTest { +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + +class CartTest { + private Cart cart; + private Product product1; + private Product product2; + @BeforeEach + public void testSetup() { + cart = new Cart(); + product1 = new Product(1, "Product 1", 1.0, 10.0, 19.0, 100); + product2 = new Product(2, "Product 2", 2.0, 20.0, 7.0, 50); + } + @Test + public void testAdd(){ + cart.addProduct(product1,2); + cart.updateProductQuantity(1,5); + assertEquals(5, cart.getPositions().get(0).getQuantity()); + + + } } \ No newline at end of file diff --git a/Shop/src/de/th_mannheim/informatik/test/java/shop/backend/ProductsTest.java b/Shop/src/de/th_mannheim/informatik/test/java/shop/backend/ProductsTest.java index 1a81ad3..0bb60ac 100644 --- a/Shop/src/de/th_mannheim/informatik/test/java/shop/backend/ProductsTest.java +++ b/Shop/src/de/th_mannheim/informatik/test/java/shop/backend/ProductsTest.java @@ -7,12 +7,25 @@ import static org.junit.jupiter.api.Assertions.*; class ProductsTest { @Test - void testConstr(){ - Product p1 = new Product(1, "Bier", 2.2, 2.90,19,2); - assertEquals(0.19, p1.mwstCalc()); + public void testGetters() { + + Product product = new Product(1, "Test Product", 1.5, 10.0, 19.0, 50); + assertEquals(1, product.getProdID()); + assertEquals("Test Product", product.getName()); + assertEquals(1.5, product.getTransportWeight()); + assertEquals(10.0, product.getNetPrice()); + assertEquals(19.0, product.getMwst()); + assertEquals(50, product.getStock()); + } + @Test + public void testEquals() { + Product product1 = new Product(1, "Bier", 1.5, 10.0, 19.0, 50); + Product product2 = new Product(2, "Bier", 2.0, 10.0, 7.0, 100); + Product product3 = new Product(3, "Mango", 1.5, 10.0, 19.0, 50); + assertTrue(product1.equals(product2)); + assertFalse(product1.equals(product3)); } - } \ No newline at end of file