From c9968722c80eb8f4fc551ac54146cb7b5beafa24 Mon Sep 17 00:00:00 2001 From: fdai6352 Date: Wed, 16 Feb 2022 18:03:46 +0100 Subject: [PATCH] implemented set numbers menu item and test refactor --- src/main/java/Vault.java | 10 +++++----- src/test/java/VaultTest.java | 17 +++++++++++------ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/java/Vault.java b/src/main/java/Vault.java index 396e861..2ed61c7 100644 --- a/src/main/java/Vault.java +++ b/src/main/java/Vault.java @@ -53,6 +53,10 @@ public class Vault implements VaultInterface { println("Should you PW have special characters? Type in yes or no."); String inputS = scan.nextLine(); setSpecialChar(inputS); + } else if (input.equals("n")) { + println("Should you PW have numbers? Type in yes or no."); + String inputN = scan.nextLine(); + setNumbers(input); } } @@ -113,11 +117,7 @@ public class Vault implements VaultInterface { } } - public void SetNumbers() { - println("Should you PW have numbers? Type in yes or no."); - - Scanner scan = new Scanner(inputS); - String input = scan.nextLine(); + public void setNumbers(String input) { if(input.equals("yes")){ hasNumbers = true; diff --git a/src/test/java/VaultTest.java b/src/test/java/VaultTest.java index 17d5a3d..95df60d 100644 --- a/src/test/java/VaultTest.java +++ b/src/test/java/VaultTest.java @@ -148,22 +148,27 @@ public class VaultTest { assertTrue(outputStream.toString().contains("don´t")); } + @Test + void openSetNumbersMenuItem() { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + vlt.inputS = new ByteArrayInputStream("h\nyes".getBytes(StandardCharsets.UTF_8)); + vlt.outputS = outputStream; + vlt.configure(); + assertTrue(vlt.hasNumbers = true); + } + @Test void setNumbersTest() { - vlt.inputS = new ByteArrayInputStream("yes\n".getBytes(StandardCharsets.UTF_8)); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); vlt.outputS = outputStream; - vlt.SetNumbers(); + vlt.setNumbers("yes"); - assertTrue(outputStream.toString().startsWith("Should")); assertTrue(vlt.hasNumbers = true); assertTrue(outputStream.toString().contains("contain")); - vlt.inputS = new ByteArrayInputStream("no\n".getBytes(StandardCharsets.UTF_8)); vlt.outputS = outputStream; - vlt.SetNumbers(); + vlt.setNumbers("no"); - assertTrue(outputStream.toString().startsWith("Should")); assertFalse(vlt.hasNumbers = false); assertTrue(outputStream.toString().contains("don´t")); }