From f8ab3d1a06c92c8f70fc9519de1fad6ebeb44a0f Mon Sep 17 00:00:00 2001 From: binsky Date: Mon, 14 Feb 2022 20:58:09 +0100 Subject: [PATCH] implement menu navigation to create a new vault --- src/main/java/PasswordManager.java | 7 +++++-- src/test/java/PasswordManagerTest.java | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/PasswordManager.java b/src/main/java/PasswordManager.java index 10cf125..d988522 100644 --- a/src/main/java/PasswordManager.java +++ b/src/main/java/PasswordManager.java @@ -58,7 +58,8 @@ public class PasswordManager implements PasswordManagerInterface { sb.append("\nciip Gruppe 8 - Password Manager\n\n"); sb.append("Menu:\n"); - sb.append("- list vaults: l:\n"); + sb.append("- list vaults: l\n"); + sb.append("- create new vault: v\n"); sb.append("- select vault: v x (replace x with vault id)\n"); sb.append("- exit: e\n"); @@ -70,7 +71,9 @@ public class PasswordManager implements PasswordManagerInterface { running = false; } else if (input.equals("l")) { listVaults(); - } else if (input.startsWith("v")) { + } else if (input.equals("v")) { + createNewVault(); + } else if (input.startsWith("v")) { String vaultAction = (input.replace('v', ' ')).trim(); int vaultId = -1; diff --git a/src/test/java/PasswordManagerTest.java b/src/test/java/PasswordManagerTest.java index 9eab2f3..d191cf1 100644 --- a/src/test/java/PasswordManagerTest.java +++ b/src/test/java/PasswordManagerTest.java @@ -49,6 +49,16 @@ class PasswordManagerTest { assertTrue(outputStream.toString().endsWith("Vaults:\n")); } + @Test + void menuNavigationCreateNewVault() { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + pm.inputStream = new ByteArrayInputStream("v\n".getBytes(StandardCharsets.UTF_8)); + pm.outputStream = outputStream; + int vaultCount = pm.vaults.size(); + pm.showMenu(); + assertEquals(vaultCount + 1, pm.vaults.size()); + } + @Test void menuNavigationOpenVault() { ByteArrayOutputStream outputStream = new ByteArrayOutputStream();