From 6d43a35632a18505e9258b5394184e1e2c75a2e7 Mon Sep 17 00:00:00 2001 From: fdai6352 Date: Wed, 16 Feb 2022 17:50:51 +0100 Subject: [PATCH] implemented set capitals in configure menu --- src/main/java/Vault.java | 14 +++++++------- src/test/java/VaultTest.java | 19 ++++++++++++------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main/java/Vault.java b/src/main/java/Vault.java index f62f188..1cdc10b 100644 --- a/src/main/java/Vault.java +++ b/src/main/java/Vault.java @@ -39,11 +39,15 @@ public class Vault implements VaultInterface { if (input.equals("e")) { config = false; - }else if (input.equals("l")) { + } else if (input.equals("l")) { println("Set PW length:"); String inputPw = scan.nextLine(); setPWLength(inputPw); - }else if (!input.equals("l")|!input.equals("e")|!input.equals("h")) { + } else if (input.equals("h")) { + println("Should your PW have capitals? Type in yes or no."); + String inputC = scan.nextLine(); + setPWLength(inputC); + } else if (!input.equals("l")|!input.equals("e")|!input.equals("h")) { println("Please enter valid key."); } @@ -83,11 +87,7 @@ public class Vault implements VaultInterface { } - public void setCapital() { - println("Should you PW have capitals? Type in yes or no."); - - Scanner scan = new Scanner(inputS); - String input = scan.nextLine(); + public void setCapital(String input) { if(input.equals("yes")){ haveCapitals = true; diff --git a/src/test/java/VaultTest.java b/src/test/java/VaultTest.java index 3d4e97e..c0a2ad7 100644 --- a/src/test/java/VaultTest.java +++ b/src/test/java/VaultTest.java @@ -110,21 +110,26 @@ public class VaultTest { } @Test - void setCapital() { - vlt.inputS = new ByteArrayInputStream("yes\n".getBytes(StandardCharsets.UTF_8)); + void openSetCapitalsMenuItem() { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + vlt.inputS = new ByteArrayInputStream("h\nyes".getBytes(StandardCharsets.UTF_8)); vlt.outputS = outputStream; - vlt.setCapital(); + vlt.configure(); + assertTrue(vlt.haveCapitals = true); + } + + @Test + void setCapitals() { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + vlt.outputS = outputStream; + vlt.setCapital("yes"); - assertTrue(outputStream.toString().startsWith("Should")); assertTrue(vlt.haveCapitals = true); assertTrue(outputStream.toString().contains("contain")); - vlt.inputS = new ByteArrayInputStream("no\n".getBytes(StandardCharsets.UTF_8)); vlt.outputS = outputStream; - vlt.setCapital(); + vlt.setCapital("no"); - assertTrue(outputStream.toString().startsWith("Should")); assertFalse(vlt.haveCapitals = false); assertTrue(outputStream.toString().contains("donĀ“t")); }