Implementeirung test für Warenkorb kleinere veränderungen
main
Fatima Zehra Ulu 2025-12-15 09:32:21 +01:00
parent 4c06b681bf
commit 13f6234dd1
3 changed files with 40 additions and 7 deletions

View File

@ -135,7 +135,6 @@ public class Cart {
double amount = GrossAmountProd () + deliveryCost () + taxDelivery(); double amount = GrossAmountProd () + deliveryCost () + taxDelivery();
return amount; return amount;
} }
@ -146,7 +145,15 @@ public class Cart {
} }
} }
public void printCart() { public String [] printCart() {
StringBuilder sb = new StringBuilder("--- Detaillierter Warenkorb ---\n");
for (Products prod : cartContents){
sb.append(prod.toString());
sb.append(prod.toString()).append("\n"); // Nutzt die toString() von Products
}
sb.append("========================\n");
sb.append(String.format("Gesamtwert (Brutto): %.2f€%n", wholeAmount()));
return new String[]{sb.toString()};
} }
} }

29
CartTest.java 100644
View File

@ -0,0 +1,29 @@
package Shop;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class CartTest {
@Test
void testEquals() {
Products p1 = new Products("Wein", 0.7, 1.2, 4.20, 19, 87);
Products p2 = new Products("Wein", 0.7, 1.2, 4.20, 19, 87);
assertTrue(p1.equals(p2));
}
@Test
void testConstructor() {
Products p1 = new Products("Wein", 0.7, 1.2, 4.20, 19, 87);
Products p2 = new Products("Kokosmilch", 250, 0.275, 1.67, 7, 12);
assertEquals("Wein", p1.getName());
assertEquals("Kokosmilch", p2.getName());
assertEquals(4.20, p1.getNetWorth());
assertEquals(1.67, p2.getNetWorth());
}
}

View File

@ -40,17 +40,14 @@ public class Shop {
} else if (eingabe.equals("produktsuche") || eingabe.equals("suche")) { } else if (eingabe.equals("produktsuche") || eingabe.equals("suche")) {
Search(); Search();
} else if (eingabe.equals("warenkorb")) { } else if (eingabe.equals("warenkorb")) {
System.out.println(" ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄"); new Cart();
System.out.println(" Auf Wiedersehen! ");
System.out.println("____________________________");
} else if (eingabe.equals("beenden")) { } else if (eingabe.equals("beenden")) {
System.out.println(" ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄"); System.out.println(" ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄");
System.out.println(" Auf Wiedersehen! "); System.out.println(" Auf Wiedersehen! ");
System.out.println("____________________________"); System.out.println("____________________________");
} else { } else {
System.out.println("\n\n Ungültige Eingabe (˃̣̣̥ᯅ˂̣̣̥) Versuchen Sie es bitte erneut:"); System.out.println("\n\n Ungültige Eingabe, Versuchen Sie es bitte erneut:");
mainMenu(); mainMenu();
} }
} }