Browse Source

refactored edit credential menu and test

feature-credential
fdai6352 3 years ago
parent
commit
92d763d836
  1. 22
      src/main/java/Vault.java
  2. 10
      src/test/java/VaultTest.java

22
src/main/java/Vault.java

@ -14,6 +14,9 @@ public class Vault implements VaultInterface {
public boolean credentialM; public boolean credentialM;
public String userName; public String userName;
public String password; public String password;
public int newID;
public String newString;
public boolean decision;
InputStream inputS = System.in; InputStream inputS = System.in;
OutputStream outputS = System.out; OutputStream outputS = System.out;
private CredentialRepository credentialRepository = new CredentialRepository(); private CredentialRepository credentialRepository = new CredentialRepository();
@ -69,7 +72,7 @@ public class Vault implements VaultInterface {
} }
} }
public void setPWLength(String pwLength){
public void setPWLength(String pwLength) {
try { try {
PWLength = Integer.parseInt(pwLength); PWLength = Integer.parseInt(pwLength);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
@ -84,7 +87,7 @@ public class Vault implements VaultInterface {
credentialRepository.createNewCredential(userName, password); credentialRepository.createNewCredential(userName, password);
} }
public void showCredential(String str){
public void showCredential(String str) {
if(str.matches("[0-9]+")) { if(str.matches("[0-9]+")) {
println("Getting credential via ID"); println("Getting credential via ID");
@ -96,6 +99,7 @@ public class Vault implements VaultInterface {
} }
} }
public void getAsJson(){ public void getAsJson(){
} }
@ -174,7 +178,19 @@ public class Vault implements VaultInterface {
showCredential(str); showCredential(str);
} else if (input.equals("l")) { } else if (input.equals("l")) {
println("Type username or ID to select credential:");
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;
}else{
decision = false;
}
println("Type new:");
newString = scan.nextLine();
//editCredential(newID, newString, decision);
} }
} }
} }

10
src/test/java/VaultTest.java

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

Loading…
Cancel
Save