From db0423a18ccb7de0d7bef52be8563da306e1200a Mon Sep 17 00:00:00 2001 From: fdai6352 Date: Wed, 16 Feb 2022 00:44:59 +0100 Subject: [PATCH] added set numbers function --- src/main/java/Vault.java | 16 ++++++++++++++++ src/test/java/VaultTest.java | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/main/java/Vault.java b/src/main/java/Vault.java index 225eea0..6b833c3 100644 --- a/src/main/java/Vault.java +++ b/src/main/java/Vault.java @@ -10,6 +10,7 @@ public class Vault implements VaultInterface { public int PWLength; public boolean haveCapitals; public boolean hasSpecialChars; + public boolean hasNumbers; InputStream inputS = System.in; OutputStream outputS = System.out; @@ -105,4 +106,19 @@ public class Vault implements VaultInterface { println("Your PWs don´t have special characters anymore."); } } + + public void SetNumbers() { + println("Should you PW have numbers? Type in yes or no."); + + Scanner scan = new Scanner(inputS); + String input = scan.nextLine(); + + if(input.equals("yes")){ + hasNumbers = true; + println("Your PWs contains now numbers."); + }else if(input.equals("no")){ + hasNumbers = false; + println("Your PWs don´t have numbers anymore."); + } + } } diff --git a/src/test/java/VaultTest.java b/src/test/java/VaultTest.java index 8aedbc3..5d5fc18 100644 --- a/src/test/java/VaultTest.java +++ b/src/test/java/VaultTest.java @@ -142,6 +142,26 @@ public class VaultTest { assertTrue(outputStream.toString().contains("don´t")); } + @Test + void setNumbersTest() { + vlt.inputS = new ByteArrayInputStream("yes\n".getBytes(StandardCharsets.UTF_8)); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + vlt.outputS = outputStream; + vlt.SetNumbers(); + + 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(); + + assertTrue(outputStream.toString().startsWith("Should")); + assertFalse(vlt.hasNumbers = false); + assertTrue(outputStream.toString().contains("don´t")); + } + private ByteArrayInputStream getEmptyStringInputStream() { return new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)); }