From 091c425ae1b83324f47df05e40351d914c3bacf9 Mon Sep 17 00:00:00 2001 From: fdai6352 Date: Sat, 5 Feb 2022 18:20:56 +0100 Subject: [PATCH 01/10] added Configuration Menu --- src/main/java/Vault.java | 26 ++++++++++++++++++++++++++ src/test/java/VaultTest.java | 29 ++++++++++++++++++++++------- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/main/java/Vault.java b/src/main/java/Vault.java index e377411..d90d0e2 100644 --- a/src/main/java/Vault.java +++ b/src/main/java/Vault.java @@ -1,6 +1,32 @@ +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.charset.StandardCharsets; +import java.util.Scanner; + public class Vault implements VaultInterface { + InputStream inputS = System.in; + OutputStream outputS = System.out; + + private void println(String output) { + try { + outputS.write((output + "\n").getBytes(StandardCharsets.UTF_8)); + } catch (IOException e) { + e.printStackTrace(); + } + } + public void configure(){ + StringBuilder sbcm = new StringBuilder(); + //Scanner scan = new Scanner(inputS); + + sbcm.append("Configure:\n"); + sbcm.append("- Passwordlength: l\n"); + sbcm.append("- Have Capitals: h\n"); + sbcm.append("- exit: e\n"); + + println(sbcm.toString()); } diff --git a/src/test/java/VaultTest.java b/src/test/java/VaultTest.java index 0b3e72f..80e003b 100644 --- a/src/test/java/VaultTest.java +++ b/src/test/java/VaultTest.java @@ -7,20 +7,22 @@ import java.io.ByteArrayOutputStream; import java.nio.charset.StandardCharsets; import java.util.NoSuchElementException; +import static org.junit.jupiter.api.Assertions.*; + public class VaultTest { - static Vault vlt; + Vault vlt = new Vault(); - @BeforeAll + /* @BeforeAll static void init() { vlt = new Vault(); - } + }*/ - /* @BeforeEach + @BeforeEach void reset() { - pm.outputStream = System.out; - pm.inputStream = System.in; - }*/ + vlt.outputS = System.out; + vlt.inputS = System.in; + } @Test void configure() {vlt.configure();} @@ -37,4 +39,17 @@ public class VaultTest { @Test void loadFromJson() {vlt.loadFromJson();} + @Test + void openConfigureMenu() { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + vlt.inputS = getEmptyStringInputStream(); + vlt.outputS = outputStream; + vlt.configure(); + assertTrue(outputStream.toString().startsWith("Configure:")); + } + + + private ByteArrayInputStream getEmptyStringInputStream() { + return new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)); + } } From 1c6d2148f2353073c6b8b824d6756e49b86fb04d Mon Sep 17 00:00:00 2001 From: fdai6352 Date: Sat, 5 Feb 2022 20:19:09 +0100 Subject: [PATCH 02/10] added Configuration Menu exit --- src/main/java/Vault.java | 11 ++++++++++- src/test/java/VaultTest.java | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/Vault.java b/src/main/java/Vault.java index d90d0e2..7f29b23 100644 --- a/src/main/java/Vault.java +++ b/src/main/java/Vault.java @@ -6,6 +6,7 @@ import java.util.Scanner; public class Vault implements VaultInterface { + public boolean config; InputStream inputS = System.in; OutputStream outputS = System.out; @@ -19,7 +20,8 @@ public class Vault implements VaultInterface { public void configure(){ StringBuilder sbcm = new StringBuilder(); - //Scanner scan = new Scanner(inputS); + Scanner scan = new Scanner(inputS); + config = true; sbcm.append("Configure:\n"); sbcm.append("- Passwordlength: l\n"); @@ -28,6 +30,13 @@ public class Vault implements VaultInterface { println(sbcm.toString()); + String input = scan.nextLine(); + + if (input.equals("e")) { + config = false; + + } + } public void addCredential(){ diff --git a/src/test/java/VaultTest.java b/src/test/java/VaultTest.java index 80e003b..f506dcc 100644 --- a/src/test/java/VaultTest.java +++ b/src/test/java/VaultTest.java @@ -48,6 +48,14 @@ public class VaultTest { assertTrue(outputStream.toString().startsWith("Configure:")); } + @Test + void exitConfigurationMenu(){ + vlt.inputS = new ByteArrayInputStream("e".getBytes(StandardCharsets.UTF_8)); + vlt.configure(); + assertFalse(vlt.config); + } + + private ByteArrayInputStream getEmptyStringInputStream() { return new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)); From 6fa8c7431325056201fa10270a40ecb1d62fa41a Mon Sep 17 00:00:00 2001 From: fdai6352 Date: Sat, 5 Feb 2022 20:28:28 +0100 Subject: [PATCH 03/10] added Configuration Menu no Exit after wrong Input --- src/main/java/Vault.java | 1 - src/test/java/VaultTest.java | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/Vault.java b/src/main/java/Vault.java index 7f29b23..7086edb 100644 --- a/src/main/java/Vault.java +++ b/src/main/java/Vault.java @@ -34,7 +34,6 @@ public class Vault implements VaultInterface { if (input.equals("e")) { config = false; - } } diff --git a/src/test/java/VaultTest.java b/src/test/java/VaultTest.java index f506dcc..b39508b 100644 --- a/src/test/java/VaultTest.java +++ b/src/test/java/VaultTest.java @@ -55,6 +55,20 @@ public class VaultTest { assertFalse(vlt.config); } + @Test + void doNotExitConfigAfterWrongInput() { + vlt.inputS = new ByteArrayInputStream("__\n".getBytes(StandardCharsets.UTF_8)); + vlt.configure(); + assertTrue(vlt.config); + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + vlt.inputS = getEmptyStringInputStream(); + vlt.outputS = outputStream; + + assertThrowsExactly(NoSuchElementException.class, () -> vlt.configure()); + assertTrue(outputStream.toString().startsWith("Configure:")); + } + private ByteArrayInputStream getEmptyStringInputStream() { From 46bd7e3f1c1c16e7a6483c8c9a5ae3f4d31cdb00 Mon Sep 17 00:00:00 2001 From: fdai6352 Date: Sun, 13 Feb 2022 13:33:38 +0100 Subject: [PATCH 04/10] Vault and VaultTest refactor --- src/main/java/Vault.java | 8 +------- src/test/java/VaultTest.java | 8 +++++--- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main/java/Vault.java b/src/main/java/Vault.java index 7086edb..e5e1944 100644 --- a/src/main/java/Vault.java +++ b/src/main/java/Vault.java @@ -24,18 +24,12 @@ public class Vault implements VaultInterface { config = true; sbcm.append("Configure:\n"); - sbcm.append("- Passwordlength: l\n"); + sbcm.append("- Password length: l\n"); sbcm.append("- Have Capitals: h\n"); sbcm.append("- exit: e\n"); println(sbcm.toString()); - String input = scan.nextLine(); - - if (input.equals("e")) { - config = false; - } - } public void addCredential(){ diff --git a/src/test/java/VaultTest.java b/src/test/java/VaultTest.java index b39508b..9bc9164 100644 --- a/src/test/java/VaultTest.java +++ b/src/test/java/VaultTest.java @@ -11,12 +11,14 @@ import static org.junit.jupiter.api.Assertions.*; public class VaultTest { - Vault vlt = new Vault(); + //Vault vlt = new Vault(); - /* @BeforeAll + static Vault vlt; + + @BeforeAll static void init() { vlt = new Vault(); - }*/ + } @BeforeEach void reset() { From b8ebd3b2f296e086f49046b0ce070e0c92d57dfc Mon Sep 17 00:00:00 2001 From: fdai6352 Date: Tue, 15 Feb 2022 16:07:41 +0100 Subject: [PATCH 05/10] VaultTest refactor --- src/test/java/VaultTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/VaultTest.java b/src/test/java/VaultTest.java index 9bc9164..7558c71 100644 --- a/src/test/java/VaultTest.java +++ b/src/test/java/VaultTest.java @@ -26,9 +26,6 @@ public class VaultTest { vlt.inputS = System.in; } - @Test - void configure() {vlt.configure();} - @Test void addCredential() {vlt.addCredential();} @@ -44,7 +41,7 @@ public class VaultTest { @Test void openConfigureMenu() { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - vlt.inputS = getEmptyStringInputStream(); + vlt.inputS = new ByteArrayInputStream("__\n".getBytes(StandardCharsets.UTF_8)); vlt.outputS = outputStream; vlt.configure(); assertTrue(outputStream.toString().startsWith("Configure:")); @@ -71,6 +68,9 @@ public class VaultTest { assertTrue(outputStream.toString().startsWith("Configure:")); } + // @Test + // void + private ByteArrayInputStream getEmptyStringInputStream() { From 6572370472a01a7dac3574d1bfb5dc2d1bc2a1f2 Mon Sep 17 00:00:00 2001 From: fdai6352 Date: Tue, 15 Feb 2022 16:41:33 +0100 Subject: [PATCH 06/10] added setPWLength Option --- src/main/java/Vault.java | 11 +++++++++++ src/test/java/VaultTest.java | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/Vault.java b/src/main/java/Vault.java index e5e1944..124c8b5 100644 --- a/src/main/java/Vault.java +++ b/src/main/java/Vault.java @@ -30,8 +30,19 @@ public class Vault implements VaultInterface { println(sbcm.toString()); + String input = scan.nextLine(); + + if (input.equals("e")) { + config = false; + } + } + public void setPWLength(){ + + } + + public void addCredential(){ } diff --git a/src/test/java/VaultTest.java b/src/test/java/VaultTest.java index 7558c71..06bf04a 100644 --- a/src/test/java/VaultTest.java +++ b/src/test/java/VaultTest.java @@ -38,6 +38,9 @@ public class VaultTest { @Test void loadFromJson() {vlt.loadFromJson();} + @Test + void setPWLength() {vlt.setPWLength();} + @Test void openConfigureMenu() { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); @@ -68,9 +71,6 @@ public class VaultTest { assertTrue(outputStream.toString().startsWith("Configure:")); } - // @Test - // void - private ByteArrayInputStream getEmptyStringInputStream() { From bc1702b9357e7015f5df9a3f41abc447f1610cdc Mon Sep 17 00:00:00 2001 From: fdai6352 Date: Tue, 15 Feb 2022 17:01:16 +0100 Subject: [PATCH 07/10] added setPWLength Option refactor --- src/main/java/Vault.java | 2 +- src/test/java/VaultTest.java | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/Vault.java b/src/main/java/Vault.java index 124c8b5..46719ea 100644 --- a/src/main/java/Vault.java +++ b/src/main/java/Vault.java @@ -39,7 +39,7 @@ public class Vault implements VaultInterface { } public void setPWLength(){ - + println("Set PW length:"); } diff --git a/src/test/java/VaultTest.java b/src/test/java/VaultTest.java index 06bf04a..4212640 100644 --- a/src/test/java/VaultTest.java +++ b/src/test/java/VaultTest.java @@ -1,6 +1,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -38,9 +39,6 @@ public class VaultTest { @Test void loadFromJson() {vlt.loadFromJson();} - @Test - void setPWLength() {vlt.setPWLength();} - @Test void openConfigureMenu() { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); @@ -71,7 +69,13 @@ public class VaultTest { assertTrue(outputStream.toString().startsWith("Configure:")); } - + @Test + void openSetPWLength() { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + vlt.outputS = outputStream; + vlt.setPWLength(); + assertTrue(outputStream.toString().startsWith("Set")); + } private ByteArrayInputStream getEmptyStringInputStream() { return new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)); From ee44e3067d3e916e779f8921f37d6d245c9c54f6 Mon Sep 17 00:00:00 2001 From: fdai6352 Date: Tue, 15 Feb 2022 17:32:23 +0100 Subject: [PATCH 08/10] 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)); } From 087e2d6b60446ba53dacf3f13ee0559e47e381ec Mon Sep 17 00:00:00 2001 From: fdai6352 Date: Tue, 15 Feb 2022 17:43:35 +0100 Subject: [PATCH 09/10] Set PWLength Functionality, proved against wrong input --- src/main/java/Vault.java | 8 +++++++- src/test/java/VaultTest.java | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/Vault.java b/src/main/java/Vault.java index 95e2c4a..772a844 100644 --- a/src/main/java/Vault.java +++ b/src/main/java/Vault.java @@ -45,7 +45,13 @@ public class Vault implements VaultInterface { Scanner scan = new Scanner(inputS); String input = scan.nextLine(); - PWLength = Integer.parseInt(input); + try { + PWLength = Integer.parseInt(input); + } catch (NumberFormatException e) { + println("Please Enter Valid Number."); + } + + println("\nNew PWlength is now: "); } diff --git a/src/test/java/VaultTest.java b/src/test/java/VaultTest.java index b64923a..fdbc0f9 100644 --- a/src/test/java/VaultTest.java +++ b/src/test/java/VaultTest.java @@ -89,6 +89,19 @@ public class VaultTest { assertTrue(outputStream.toString().contains("now:")); } + @Test + void setPWLengthWrongInput() { + vlt.inputS = new ByteArrayInputStream("T\n".getBytes(StandardCharsets.UTF_8)); + vlt.setPWLength(); + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + vlt.inputS = getEmptyStringInputStream(); + vlt.outputS = outputStream; + + assertThrowsExactly(NoSuchElementException.class, () -> vlt.setPWLength()); + assertTrue(outputStream.toString().startsWith("Set")); + } + private ByteArrayInputStream getEmptyStringInputStream() { return new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)); } From df02d33f556a100e23ac92a56e444797fd193db2 Mon Sep 17 00:00:00 2001 From: fdai6352 Date: Tue, 15 Feb 2022 18:10:48 +0100 Subject: [PATCH 10/10] added Set Capital function --- src/main/java/Vault.java | 15 +++++++++++++++ src/test/java/VaultTest.java | 20 ++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/main/java/Vault.java b/src/main/java/Vault.java index 772a844..4405ee1 100644 --- a/src/main/java/Vault.java +++ b/src/main/java/Vault.java @@ -8,6 +8,7 @@ public class Vault implements VaultInterface { public boolean config; public int PWLength; + public boolean haveCapitals = false; InputStream inputS = System.in; OutputStream outputS = System.out; @@ -73,4 +74,18 @@ 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(); + + if(input.equals("yes")){ + haveCapitals = true; + println("Your PWs contain now capitals."); + }else if(input.equals("no")){ + haveCapitals = false; + println("Your PWs don´t have capitals anymore."); + } + } } diff --git a/src/test/java/VaultTest.java b/src/test/java/VaultTest.java index fdbc0f9..dcb0668 100644 --- a/src/test/java/VaultTest.java +++ b/src/test/java/VaultTest.java @@ -102,6 +102,26 @@ public class VaultTest { assertTrue(outputStream.toString().startsWith("Set")); } + @Test + void setCapital() { + vlt.inputS = new ByteArrayInputStream("yes\n".getBytes(StandardCharsets.UTF_8)); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + vlt.outputS = outputStream; + vlt.setCapital(); + + 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(); + + assertTrue(outputStream.toString().startsWith("Should")); + assertFalse(vlt.haveCapitals = false); + assertTrue(outputStream.toString().contains("don´t")); + } + private ByteArrayInputStream getEmptyStringInputStream() { return new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)); }