diff --git a/src/main/java/PasswordManager.java b/src/main/java/PasswordManager.java index 0a16d66..ddc68c9 100644 --- a/src/main/java/PasswordManager.java +++ b/src/main/java/PasswordManager.java @@ -1,14 +1,18 @@ -import java.io.BufferedInputStream; import java.io.InputStream; +import java.util.Scanner; public class PasswordManager implements PasswordManagerInterface { + + boolean running = true; + public static void main(String[] args) { PasswordManager pm = new PasswordManager(); - while (true) { + while (pm.running) { InputStream inputStream = System.in; pm.showMenu(inputStream); } + System.exit(0); } public PasswordManager() { @@ -27,6 +31,20 @@ public class PasswordManager implements PasswordManagerInterface { @Override public void showMenu(InputStream inputStream) { + StringBuilder sb = new StringBuilder(); + Scanner scan = new Scanner(inputStream); + + sb.append("ciip Gruppe 8 - Password Manager\n\n"); + + sb.append("Menu:\n"); + sb.append("- exit: e\n"); + System.out.println(sb + "\n"); + + String input = scan.nextLine(); + + if (input.equals("e")) { + running = false; + } } } diff --git a/src/test/java/PasswordManagerTest.java b/src/test/java/PasswordManagerTest.java index 7f3bc47..81e4427 100644 --- a/src/test/java/PasswordManagerTest.java +++ b/src/test/java/PasswordManagerTest.java @@ -4,6 +4,7 @@ import org.junit.jupiter.api.Test; import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.nio.charset.StandardCharsets; +import java.util.NoSuchElementException; import static org.junit.jupiter.api.Assertions.*; @@ -34,6 +35,13 @@ class PasswordManagerTest { @Test void showMenu() { - pm.showMenu(new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8))); + ByteArrayInputStream virtualConsoleInput = new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)); + assertThrowsExactly(NoSuchElementException.class, () -> pm.showMenu(virtualConsoleInput)); + } + + @Test + void exitMenu() { + pm.showMenu(new ByteArrayInputStream("e\n".getBytes(StandardCharsets.UTF_8))); + assertFalse(pm.running); } }