#Fix - Cart Add bug fix

#TEST - Cart Test implemetiert
#TEST - ProductsTest implementiert
main
Daniel Zikol 2025-12-15 06:36:12 +01:00
parent 61252aae03
commit fc3ef498e2
5 changed files with 48 additions and 9 deletions

View File

@ -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) {

View File

@ -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<CartPosition> 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) {

View File

@ -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();

View File

@ -1,5 +1,26 @@
package shop.backend;
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());
}
}

View File

@ -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));
}
}