From 6b50608ef8567a73e493d7078e282f3643d485db Mon Sep 17 00:00:00 2001 From: fdai6352 Date: Thu, 17 Feb 2022 00:31:17 +0100 Subject: [PATCH] refactored credential menu exit --- src/main/java/Vault.java | 8 ++++++++ src/test/java/VaultTest.java | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/main/java/Vault.java b/src/main/java/Vault.java index 463ea5d..06ea8de 100644 --- a/src/main/java/Vault.java +++ b/src/main/java/Vault.java @@ -124,6 +124,8 @@ public class Vault implements VaultInterface { public void credentialMenu() { StringBuilder sbcm = new StringBuilder(); + Scanner scan = new Scanner(inputS); + credentialM = true; sbcm.append("Configure credentials:\n"); sbcm.append("- add credential: a\n"); @@ -131,5 +133,11 @@ public class Vault implements VaultInterface { sbcm.append("- exit: e\n"); println(sbcm.toString()); + + String input = scan.nextLine(); + + if (input.equals("e")) { + credentialM = false; + } } } diff --git a/src/test/java/VaultTest.java b/src/test/java/VaultTest.java index 738afef..5400a53 100644 --- a/src/test/java/VaultTest.java +++ b/src/test/java/VaultTest.java @@ -30,8 +30,10 @@ public class VaultTest { @Test void openCredentialMenu() { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + vlt.inputS = new ByteArrayInputStream("__\n".getBytes(StandardCharsets.UTF_8)); vlt.outputS = outputStream; vlt.credentialMenu(); + assertTrue(vlt.credentialM); assertTrue(outputStream.toString().startsWith("Configure")); }