From f89a4e4af103d8ce7f7b3a1a2acf1eef86d9df97 Mon Sep 17 00:00:00 2001 From: fdai6352 Date: Thu, 17 Feb 2022 01:34:08 +0100 Subject: [PATCH] implemented add credential functionality --- src/main/java/Vault.java | 9 +++++++++ src/test/java/VaultTest.java | 12 +++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/Vault.java b/src/main/java/Vault.java index ffeadee..b66b615 100644 --- a/src/main/java/Vault.java +++ b/src/main/java/Vault.java @@ -12,6 +12,8 @@ public class Vault implements VaultInterface { public boolean hasSpecialChars; public boolean hasNumbers; public boolean credentialM; + public String userName; + public String password; InputStream inputS = System.in; OutputStream outputS = System.out; @@ -72,6 +74,13 @@ public class Vault implements VaultInterface { public void addCredential(){ + Scanner scan = new Scanner(inputS); + println("Type in username"); + userName = scan.nextLine(); + + println("Type in password"); + password = scan.nextLine(); + //createNewCredential(userName, password); } diff --git a/src/test/java/VaultTest.java b/src/test/java/VaultTest.java index ea2d381..3a820a5 100644 --- a/src/test/java/VaultTest.java +++ b/src/test/java/VaultTest.java @@ -72,7 +72,17 @@ public class VaultTest { } @Test - void addCredentialTest() { vlt.addCredential();} + void addCredentialTest() { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + vlt.outputS = outputStream; + vlt.inputS = new ByteArrayInputStream("peter\npassword".getBytes(StandardCharsets.UTF_8)); + vlt.addCredential(); + + assertTrue(outputStream.toString().contains("username")); + assertEquals("peter", vlt.userName); + assertTrue(outputStream.toString().contains("password")); + assertEquals("password",vlt.password); + } @Test void showCredential() {vlt.showCredential();}