Browse Source

refactored showCredential for better compatibility

feature-credential
fdai6352 3 years ago
parent
commit
779d94e9a7
  1. 11
      src/main/java/Vault.java
  2. 2
      src/main/java/VaultInterface.java
  3. 20
      src/test/java/VaultTest.java

11
src/main/java/Vault.java

@ -104,7 +104,11 @@ public class Vault implements VaultInterface {
credentialRepository.createNewCredential(userName, password); credentialRepository.createNewCredential(userName, password);
} }
public void showCredential(String str) {
public void showCredential() {
Scanner scan = new Scanner(inputS);
println("Type in ID or username");
String str = scan.nextLine();
if(str.matches("[0-9]+")) { if(str.matches("[0-9]+")) {
println("Getting credential via ID"); println("Getting credential via ID");
@ -193,10 +197,7 @@ public class Vault implements VaultInterface {
break; break;
case "c": case "c":
println("Type in ID or username");
String str = scan.nextLine();
showCredential(str);
showCredential();
break; break;
case "l": case "l":

2
src/main/java/VaultInterface.java

@ -4,7 +4,7 @@ public interface VaultInterface {
void configure(); void configure();
void addCredential(); void addCredential();
void showCredential(String str);
void showCredential();
void getAsJson(); void getAsJson();
void loadFromJson(); void loadFromJson();
} }

20
src/test/java/VaultTest.java

@ -51,14 +51,14 @@ public class VaultTest {
assertTrue(outputStream.toString().contains("Add")); assertTrue(outputStream.toString().contains("Add"));
}*/ }*/
@Test
/*@Test
void openShowCredentialMenuItem() { void openShowCredentialMenuItem() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = new ByteArrayInputStream("c\n1".getBytes(StandardCharsets.UTF_8)); vlt.inputS = new ByteArrayInputStream("c\n1".getBytes(StandardCharsets.UTF_8));
vlt.outputS = outputStream; vlt.outputS = outputStream;
vlt.credentialMenu(); vlt.credentialMenu();
assertTrue(outputStream.toString().contains("Type")); assertTrue(outputStream.toString().contains("Type"));
}
}*/
@Test @Test
void openEditCredentialMenuItem() { void openEditCredentialMenuItem() {
@ -90,18 +90,20 @@ public class VaultTest {
assertEquals("password",vlt.password); assertEquals("password",vlt.password);
} }
/* @Test
@Test
void showCredentialTest() { void showCredentialTest() {
vlt.inputS = new ByteArrayInputStream("l\n1".getBytes(StandardCharsets.UTF_8));
vlt.showCredential();credential();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.outputS = outputStream;
vlt.inputS = new ByteArrayInputStream("1".getBytes(StandardCharsets.UTF_8));
vlt.showCredential();
assertTrue(outputStream.toString().contains("username"));
assertTrue(outputStream.toString().contains("ID"));
vlt.inputS = new ByteArrayInputStream("l\npeter".getBytes(StandardCharsets.UTF_8));
vlt.inputS = new ByteArrayInputStream("peter".getBytes(StandardCharsets.UTF_8));
vlt.credentialMenu(); vlt.credentialMenu();
assertFalse(vlt.isInt);
}*/
assertTrue(outputStream.toString().contains("name"));
}
@Test @Test

Loading…
Cancel
Save