From ee44e3067d3e916e779f8921f37d6d245c9c54f6 Mon Sep 17 00:00:00 2001 From: fdai6352 Date: Tue, 15 Feb 2022 17:32:23 +0100 Subject: [PATCH] added Set PWLength Funtionality --- src/main/java/Vault.java | 8 ++++++++ src/test/java/VaultTest.java | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/main/java/Vault.java b/src/main/java/Vault.java index 46719ea..95e2c4a 100644 --- a/src/main/java/Vault.java +++ b/src/main/java/Vault.java @@ -7,6 +7,7 @@ import java.util.Scanner; public class Vault implements VaultInterface { public boolean config; + public int PWLength; InputStream inputS = System.in; OutputStream outputS = System.out; @@ -40,6 +41,13 @@ public class Vault implements VaultInterface { public void setPWLength(){ println("Set PW length:"); + + Scanner scan = new Scanner(inputS); + String input = scan.nextLine(); + + PWLength = Integer.parseInt(input); + + println("\nNew PWlength is now: "); } diff --git a/src/test/java/VaultTest.java b/src/test/java/VaultTest.java index 4212640..b64923a 100644 --- a/src/test/java/VaultTest.java +++ b/src/test/java/VaultTest.java @@ -72,11 +72,23 @@ public class VaultTest { @Test void openSetPWLength() { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + vlt.inputS = new ByteArrayInputStream("12".getBytes(StandardCharsets.UTF_8)); vlt.outputS = outputStream; vlt.setPWLength(); assertTrue(outputStream.toString().startsWith("Set")); } + @Test + void setPWLength() { + vlt.inputS = new ByteArrayInputStream("7\n".getBytes(StandardCharsets.UTF_8)); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + vlt.outputS = outputStream; + vlt.setPWLength(); + + assertEquals(7, vlt.PWLength); + assertTrue(outputStream.toString().contains("now:")); + } + private ByteArrayInputStream getEmptyStringInputStream() { return new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)); }