From 6fa8c7431325056201fa10270a40ecb1d62fa41a Mon Sep 17 00:00:00 2001 From: fdai6352 Date: Sat, 5 Feb 2022 20:28:28 +0100 Subject: [PATCH] added Configuration Menu no Exit after wrong Input --- src/main/java/Vault.java | 1 - src/test/java/VaultTest.java | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/Vault.java b/src/main/java/Vault.java index 7f29b23..7086edb 100644 --- a/src/main/java/Vault.java +++ b/src/main/java/Vault.java @@ -34,7 +34,6 @@ public class Vault implements VaultInterface { if (input.equals("e")) { config = false; - } } diff --git a/src/test/java/VaultTest.java b/src/test/java/VaultTest.java index f506dcc..b39508b 100644 --- a/src/test/java/VaultTest.java +++ b/src/test/java/VaultTest.java @@ -55,6 +55,20 @@ public class VaultTest { assertFalse(vlt.config); } + @Test + void doNotExitConfigAfterWrongInput() { + vlt.inputS = new ByteArrayInputStream("__\n".getBytes(StandardCharsets.UTF_8)); + vlt.configure(); + assertTrue(vlt.config); + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + vlt.inputS = getEmptyStringInputStream(); + vlt.outputS = outputStream; + + assertThrowsExactly(NoSuchElementException.class, () -> vlt.configure()); + assertTrue(outputStream.toString().startsWith("Configure:")); + } + private ByteArrayInputStream getEmptyStringInputStream() {