From cd1e7a85a841c1c0b06fcfbaad1a6d8e65723843 Mon Sep 17 00:00:00 2001 From: fdai6352 Date: Wed, 16 Feb 2022 14:26:05 +0100 Subject: [PATCH] implemented userName for new credentials --- src/main/java/Vault.java | 8 ++++++++ src/test/java/VaultTest.java | 12 +++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/Vault.java b/src/main/java/Vault.java index 6b833c3..0bd630b 100644 --- a/src/main/java/Vault.java +++ b/src/main/java/Vault.java @@ -11,6 +11,7 @@ public class Vault implements VaultInterface { public boolean haveCapitals; public boolean hasSpecialChars; public boolean hasNumbers; + public String userName; InputStream inputS = System.in; OutputStream outputS = System.out; @@ -61,6 +62,13 @@ public class Vault implements VaultInterface { public void addCredential(){ + println("Add user name"); + + Scanner scan = new Scanner(inputS); + String input = scan.nextLine(); + + userName = input; + } diff --git a/src/test/java/VaultTest.java b/src/test/java/VaultTest.java index 5d5fc18..a4e95ec 100644 --- a/src/test/java/VaultTest.java +++ b/src/test/java/VaultTest.java @@ -28,7 +28,17 @@ public class VaultTest { } @Test - void addCredential() {vlt.addCredential();} + void addCredentialTest() { + String expected = "user"; + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + vlt.inputS = new ByteArrayInputStream(expected.getBytes(StandardCharsets.UTF_8)); + vlt.outputS = outputStream; + vlt.addCredential(); + + assertTrue(outputStream.toString().startsWith("Add")); + assertEquals(expected, vlt.userName); + + } @Test void showCredential() {vlt.showCredential();}