Browse Source

refactored editCredential for better compatibility

feature-credential
fdai6352 2 years ago
parent
commit
c801f9f32c
  1. 38
      src/main/java/Vault.java
  2. 22
      src/test/java/VaultTest.java

38
src/main/java/Vault.java

@ -120,10 +120,31 @@ public class Vault implements VaultInterface {
}
}
public void editCredential(int newID, String newString, boolean decision) {
if(decision == true){
public void editCredential() {
Scanner scan = new Scanner(inputS);
println("Type ID to select credential:");
newID = Integer.parseInt(scan.nextLine());
println("-change username: u\n-change password: p");
String input = scan.nextLine();
if (input.equals("u")) {
decision = true;
}
if(decision){
println("Type new username:");
newString = scan.nextLine();
credentialRepository.updateUsername(newID, newString);
} else {
println("Type new password:");
newString = scan.nextLine();
credentialRepository.updatePassword(newID, newString);
}
}
@ -201,18 +222,7 @@ public class Vault implements VaultInterface {
break;
case "l":
println("Type ID to select credential:");
newID = Integer.parseInt(scan.nextLine());
println("-change username: u\n-change password: p");
input = scan.nextLine();
if (input.equals("u")) {
decision = true;
}
println("Type new:");
newString = scan.nextLine();
editCredential(newID, newString, decision);
editCredential();
break;
}
}

22
src/test/java/VaultTest.java

@ -60,7 +60,7 @@ public class VaultTest {
assertTrue(outputStream.toString().contains("Type"));
}*/
@Test
/*@Test
void openEditCredentialMenuItem() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = new ByteArrayInputStream("l\n1\nu\npeter".getBytes(StandardCharsets.UTF_8));
@ -70,12 +70,26 @@ public class VaultTest {
assertEquals(1,vlt.newID);
assertTrue(vlt.decision);
assertEquals("peter",vlt.newString);
}
}*/
/*@Test
@Test
void editCredentialTest() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.outputS = outputStream;
vlt.inputS = new ByteArrayInputStream("1\np\npassword".getBytes(StandardCharsets.UTF_8));
vlt.editCredential();
}*/
assertEquals(1, vlt.newID);
assertEquals("password", vlt.newString);
vlt.inputS = new ByteArrayInputStream("1\nu\npeter".getBytes(StandardCharsets.UTF_8));
vlt.editCredential();
assertEquals(1, vlt.newID);
assertEquals("peter", vlt.newString);
}
@Test
void addCredentialTest() {

Loading…
Cancel
Save