Browse Source

refactored show credential method and test

feature-credential
fdai6352 3 years ago
parent
commit
b7a44828cf
  1. 5
      src/main/java/Vault.java
  2. 18
      src/test/java/VaultTest.java

5
src/main/java/Vault.java

@ -14,7 +14,6 @@ public class Vault implements VaultInterface {
public boolean credentialM; public boolean credentialM;
public String userName; public String userName;
public String password; public String password;
public boolean isInt = false;
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();
@ -88,9 +87,11 @@ public class Vault implements VaultInterface {
public void showCredential(String str){ public void showCredential(String str){
if(str.matches("[0-9]+")) { if(str.matches("[0-9]+")) {
isInt = true;
println("Getting credential via ID");
credentialRepository.getCredentialsViaId(Integer.parseInt(str)); credentialRepository.getCredentialsViaId(Integer.parseInt(str));
} else { } else {
println("Getting credential via name");
credentialRepository.getCredentialsViaName(str); credentialRepository.getCredentialsViaName(str);
} }
} }

18
src/test/java/VaultTest.java

@ -86,26 +86,22 @@ public class VaultTest {
assertEquals("peter", vlt.userName); assertEquals("peter", vlt.userName);
assertTrue(outputStream.toString().contains("password")); assertTrue(outputStream.toString().contains("password"));
assertEquals("password",vlt.password); assertEquals("password",vlt.password);
}
}*/
@Test
/*@Test
void showCredentialTest() { void showCredentialTest() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.outputS = outputStream;
vlt.inputS = new ByteArrayInputStream("1".getBytes(StandardCharsets.UTF_8));
vlt.showCredential();
vlt.inputS = new ByteArrayInputStream("l\n1".getBytes(StandardCharsets.UTF_8));
vlt.credentialMenu();
assertTrue(outputStream.toString().contains("Type"));
assertTrue(vlt.isInt); assertTrue(vlt.isInt);
vlt.outputS = outputStream;
vlt.inputS = new ByteArrayInputStream("peter".getBytes(StandardCharsets.UTF_8));
vlt.showCredential();
vlt.inputS = new ByteArrayInputStream("l\npeter".getBytes(StandardCharsets.UTF_8));
vlt.credentialMenu();
assertTrue(outputStream.toString().contains("Type"));
assertFalse(vlt.isInt); assertFalse(vlt.isInt);
}*/ }*/
@Test @Test
void getAsJson() {vlt.getAsJson();} void getAsJson() {vlt.getAsJson();}

Loading…
Cancel
Save