Browse Source

implement menu navigation to create a new vault

feature-create-new-vault
binsky 3 years ago
parent
commit
f8ab3d1a06
  1. 5
      src/main/java/PasswordManager.java
  2. 10
      src/test/java/PasswordManagerTest.java

5
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("\nciip Gruppe 8 - Password Manager\n\n");
sb.append("Menu:\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("- select vault: v x (replace x with vault id)\n");
sb.append("- exit: e\n"); sb.append("- exit: e\n");
@ -70,6 +71,8 @@ public class PasswordManager implements PasswordManagerInterface {
running = false; running = false;
} else if (input.equals("l")) { } else if (input.equals("l")) {
listVaults(); listVaults();
} else if (input.equals("v")) {
createNewVault();
} else if (input.startsWith("v")) { } else if (input.startsWith("v")) {
String vaultAction = (input.replace('v', ' ')).trim(); String vaultAction = (input.replace('v', ' ')).trim();
int vaultId = -1; int vaultId = -1;

10
src/test/java/PasswordManagerTest.java

@ -49,6 +49,16 @@ class PasswordManagerTest {
assertTrue(outputStream.toString().endsWith("Vaults:\n")); 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 @Test
void menuNavigationOpenVault() { void menuNavigationOpenVault() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

Loading…
Cancel
Save