From df02d33f556a100e23ac92a56e444797fd193db2 Mon Sep 17 00:00:00 2001 From: fdai6352 Date: Tue, 15 Feb 2022 18:10:48 +0100 Subject: [PATCH] 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)); }