From 044d4af70774c80cee8ae38c0d1612e8cd96d90a Mon Sep 17 00:00:00 2001 From: fdai6352 Date: Thu, 17 Feb 2022 01:49:04 +0100 Subject: [PATCH] implemented show credential via ID functionality --- src/main/java/Vault.java | 10 ++++++++++ src/test/java/VaultTest.java | 10 +++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/Vault.java b/src/main/java/Vault.java index b66b615..e504a64 100644 --- a/src/main/java/Vault.java +++ b/src/main/java/Vault.java @@ -14,6 +14,7 @@ public class Vault implements VaultInterface { public boolean credentialM; public String userName; public String password; + public boolean isInt = false; InputStream inputS = System.in; OutputStream outputS = System.out; @@ -85,6 +86,15 @@ public class Vault implements VaultInterface { } public void showCredential(){ + Scanner scan = new Scanner(inputS); + println("Type in ID or username"); + + String str = scan.nextLine(); + + if(str.matches("[0-9]+")) { + isInt = true; + //getCredentialsViaId(Integer.parseInt(str)); + } } diff --git a/src/test/java/VaultTest.java b/src/test/java/VaultTest.java index 3a820a5..0116dc1 100644 --- a/src/test/java/VaultTest.java +++ b/src/test/java/VaultTest.java @@ -85,7 +85,15 @@ public class VaultTest { } @Test - void showCredential() {vlt.showCredential();} + void showCredentialTest() { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + vlt.outputS = outputStream; + vlt.inputS = new ByteArrayInputStream("1".getBytes(StandardCharsets.UTF_8)); + vlt.showCredential(); + + assertTrue(outputStream.toString().contains("Type")); + assertTrue(vlt.isInt); + } @Test void getAsJson() {vlt.getAsJson();}