From 091c425ae1b83324f47df05e40351d914c3bacf9 Mon Sep 17 00:00:00 2001 From: fdai6352 Date: Sat, 5 Feb 2022 18:20:56 +0100 Subject: [PATCH] added Configuration Menu --- src/main/java/Vault.java | 26 ++++++++++++++++++++++++++ src/test/java/VaultTest.java | 29 ++++++++++++++++++++++------- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/main/java/Vault.java b/src/main/java/Vault.java index e377411..d90d0e2 100644 --- a/src/main/java/Vault.java +++ b/src/main/java/Vault.java @@ -1,6 +1,32 @@ +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.charset.StandardCharsets; +import java.util.Scanner; + public class Vault implements VaultInterface { + InputStream inputS = System.in; + OutputStream outputS = System.out; + + private void println(String output) { + try { + outputS.write((output + "\n").getBytes(StandardCharsets.UTF_8)); + } catch (IOException e) { + e.printStackTrace(); + } + } + public void configure(){ + StringBuilder sbcm = new StringBuilder(); + //Scanner scan = new Scanner(inputS); + + sbcm.append("Configure:\n"); + sbcm.append("- Passwordlength: l\n"); + sbcm.append("- Have Capitals: h\n"); + sbcm.append("- exit: e\n"); + + println(sbcm.toString()); } diff --git a/src/test/java/VaultTest.java b/src/test/java/VaultTest.java index 0b3e72f..80e003b 100644 --- a/src/test/java/VaultTest.java +++ b/src/test/java/VaultTest.java @@ -7,20 +7,22 @@ import java.io.ByteArrayOutputStream; import java.nio.charset.StandardCharsets; import java.util.NoSuchElementException; +import static org.junit.jupiter.api.Assertions.*; + public class VaultTest { - static Vault vlt; + Vault vlt = new Vault(); - @BeforeAll + /* @BeforeAll static void init() { vlt = new Vault(); - } + }*/ - /* @BeforeEach + @BeforeEach void reset() { - pm.outputStream = System.out; - pm.inputStream = System.in; - }*/ + vlt.outputS = System.out; + vlt.inputS = System.in; + } @Test void configure() {vlt.configure();} @@ -37,4 +39,17 @@ public class VaultTest { @Test void loadFromJson() {vlt.loadFromJson();} + @Test + void openConfigureMenu() { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + vlt.inputS = getEmptyStringInputStream(); + vlt.outputS = outputStream; + vlt.configure(); + assertTrue(outputStream.toString().startsWith("Configure:")); + } + + + private ByteArrayInputStream getEmptyStringInputStream() { + return new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)); + } }