parent
fdcb71bd46
commit
e21aa4f283
|
|
@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue