From e21aa4f28384fe84792d5efd874a5bf0fddb8f39 Mon Sep 17 00:00:00 2001 From: Fatima Zehra Ulu <3026753@stud.hs-mannheim.de> Date: Fri, 19 Dec 2025 12:14:54 +0100 Subject: [PATCH] Dateien nach "/" hochladen UI mit tests --- shopTUI.java | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ shopTUITest.java | 42 ++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 shopTUI.java create mode 100644 shopTUITest.java diff --git a/shopTUI.java b/shopTUI.java new file mode 100644 index 0000000..40fc0de --- /dev/null +++ b/shopTUI.java @@ -0,0 +1,59 @@ +package pckg; +import pckg.Backend.OnlineShop; +import pckg.Backend.Warenkorb; + +import java.util.Scanner; +import java.io.FileNotFoundException; + + +public class shopTUI { + + private OnlineShop shop; + private Scanner sc = new Scanner(System.in); + + public void main(String[] args) throws FileNotFoundException { + System.out.println("Willkommen bei Ihrem vertreiber für Alltägliches"); + + shop = new OnlineShop(); + mainMenu(); + } + + public void mainMenu() throws FileNotFoundException { + System.out.println("\n-----------Hauptmenü-----------"); + System.out.println("----------------------------------"); + System.out.println(" Produktangebot "); + System.out.println(" Produktsuche "); + System.out.println(" Warenkorb "); + System.out.println(" Beenden "); + System.out.println("-----------------------------------\n"); + System.out.print("Bitte geben Sie eine der Optionen an: "); + + boolean rekursiv = true; + while(rekursiv){ + System.out.println("\nWas möchten Sie tun? (produktangebot, produktsuche, warenkorb, beenden): "); + String eingabe = sc.nextLine().toLowerCase(); + switch (eingabe) { + case "produktangebot": + shop.angebot(); + // Nach shop.angebot() springt er automatisch zum Schleifenanfang + break; + + case "produktsuche": + shop.suche(); + break; + + case "warenkorb": + shop.showCart(); + break; + + case "beenden": + System.out.println("\n Auf Wiedersehen! "); + rekursiv = false; // Beendet die Schleife + break; + + default: + System.out.println("\nUngültige Eingabe, bitte versuchen Sie es erneut."); + } + } + } +} diff --git a/shopTUITest.java b/shopTUITest.java new file mode 100644 index 0000000..a75aa7a --- /dev/null +++ b/shopTUITest.java @@ -0,0 +1,42 @@ +package pckg; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.io.FileNotFoundException; + +class shopTUITest { + + private shopTUI tui; + + @BeforeEach + void setUp() { + tui = new shopTUI(); + } + + @Test + void testBeendenLogik() throws FileNotFoundException { + // Wir simulieren die Eingabe "beenden", damit die Endlosschleife direkt stoppt + String input = "beenden\n"; + InputStream in = new ByteArrayInputStream(input.getBytes()); + System.setIn(in); + + // Der Test ist erfolgreich, wenn die Methode ohne Endlosschleife durchläuft + assertDoesNotThrow(() -> { + // Da mainMenu() die Schleife enthält, testen wir das Beenden hier + tui.mainMenu(); + }); + } + + @Test + void testUngueltigeEingabeUndDannBeenden() throws FileNotFoundException { + // Erst eine falsche Eingabe, dann beenden + String input = "falscheEingabe\nbeenden\n"; + InputStream in = new ByteArrayInputStream(input.getBytes()); + System.setIn(in); + + assertDoesNotThrow(() -> tui.mainMenu()); + } +} \ No newline at end of file