From dfffc3c84a6e0fd5a78e8a2076df8d47e2be28b8 Mon Sep 17 00:00:00 2001 From: fdai6352 Date: Wed, 16 Feb 2022 00:42:09 +0100 Subject: [PATCH] added set special characters function and VaultInterface refactor --- src/main/java/Vault.java | 21 +++++++++++++++++++-- src/main/java/VaultInterface.java | 11 +++++------ src/test/java/VaultTest.java | 20 ++++++++++++++++++++ 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/main/java/Vault.java b/src/main/java/Vault.java index 4405ee1..225eea0 100644 --- a/src/main/java/Vault.java +++ b/src/main/java/Vault.java @@ -8,7 +8,8 @@ public class Vault implements VaultInterface { public boolean config; public int PWLength; - public boolean haveCapitals = false; + public boolean haveCapitals; + public boolean hasSpecialChars; InputStream inputS = System.in; OutputStream outputS = System.out; @@ -75,7 +76,7 @@ public class Vault implements VaultInterface { } public void setCapital() { - println("Should you PW have Capitals? Type in yes or no."); + println("Should you PW have capitals? Type in yes or no."); Scanner scan = new Scanner(inputS); String input = scan.nextLine(); @@ -88,4 +89,20 @@ public class Vault implements VaultInterface { println("Your PWs don´t have capitals anymore."); } } + + + public void setSpecialChar() { + println("Should you PW have special characters? Type in yes or no."); + + Scanner scan = new Scanner(inputS); + String input = scan.nextLine(); + + if(input.equals("yes")){ + hasSpecialChars = true; + println("Your PWs contain now special characters."); + }else if(input.equals("no")){ + hasSpecialChars = false; + println("Your PWs don´t have special characters anymore."); + } + } } diff --git a/src/main/java/VaultInterface.java b/src/main/java/VaultInterface.java index 50bbd1d..9f1fc26 100644 --- a/src/main/java/VaultInterface.java +++ b/src/main/java/VaultInterface.java @@ -2,10 +2,9 @@ public interface VaultInterface { - public void configure(); - public void addCredential(); - public void showCredential(); - public void getAsJson(); - public void loadFromJson(); - + void configure(); + void addCredential(); + void showCredential(); + void getAsJson(); + void loadFromJson(); } diff --git a/src/test/java/VaultTest.java b/src/test/java/VaultTest.java index dcb0668..8aedbc3 100644 --- a/src/test/java/VaultTest.java +++ b/src/test/java/VaultTest.java @@ -122,6 +122,26 @@ public class VaultTest { assertTrue(outputStream.toString().contains("don´t")); } + @Test + void setSpecialCharTest() { + vlt.inputS = new ByteArrayInputStream("yes\n".getBytes(StandardCharsets.UTF_8)); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + vlt.outputS = outputStream; + vlt.setSpecialChar(); + + assertTrue(outputStream.toString().startsWith("Should")); + assertTrue(vlt.hasSpecialChars = true); + assertTrue(outputStream.toString().contains("contain")); + + vlt.inputS = new ByteArrayInputStream("no\n".getBytes(StandardCharsets.UTF_8)); + vlt.outputS = outputStream; + vlt.setSpecialChar(); + + assertTrue(outputStream.toString().startsWith("Should")); + assertFalse(vlt.hasSpecialChars = false); + assertTrue(outputStream.toString().contains("don´t")); + } + private ByteArrayInputStream getEmptyStringInputStream() { return new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)); }