3 Commits

  1. 22
      src/main/java/Vault.java
  2. 29
      src/test/java/VaultTest.java

22
src/main/java/Vault.java

@ -12,6 +12,9 @@ public class Vault implements VaultInterface {
public boolean hasSpecialChars; public boolean hasSpecialChars;
public boolean hasNumbers; public boolean hasNumbers;
public boolean credentialM; public boolean credentialM;
public String userName;
public String password;
public boolean isInt = false;
InputStream inputS = System.in; InputStream inputS = System.in;
OutputStream outputS = System.out; OutputStream outputS = System.out;
@ -72,10 +75,29 @@ public class Vault implements VaultInterface {
public void addCredential(){ public void addCredential(){
Scanner scan = new Scanner(inputS);
println("Type in username");
userName = scan.nextLine();
println("Type in password");
password = scan.nextLine();
//createNewCredential(userName, password);
} }
public void showCredential(){ public void showCredential(){
Scanner scan = new Scanner(inputS);
println("Type in ID or username");
String str = scan.nextLine();
if(str.matches("[0-9]+")) {
isInt = true;
//getCredentialsViaId(Integer.parseInt(str));
} else {
isInt = false;
//getCredentialsViaName(str);
}
} }

29
src/test/java/VaultTest.java

@ -72,10 +72,35 @@ public class VaultTest {
} }
@Test @Test
void addCredentialTest() { vlt.addCredential();}
void addCredentialTest() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.outputS = outputStream;
vlt.inputS = new ByteArrayInputStream("peter\npassword".getBytes(StandardCharsets.UTF_8));
vlt.addCredential();
assertTrue(outputStream.toString().contains("username"));
assertEquals("peter", vlt.userName);
assertTrue(outputStream.toString().contains("password"));
assertEquals("password",vlt.password);
}
@Test @Test
void showCredential() {vlt.showCredential();}
void showCredentialTest() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.outputS = outputStream;
vlt.inputS = new ByteArrayInputStream("1".getBytes(StandardCharsets.UTF_8));
vlt.showCredential();
assertTrue(outputStream.toString().contains("Type"));
assertTrue(vlt.isInt);
vlt.outputS = outputStream;
vlt.inputS = new ByteArrayInputStream("peter".getBytes(StandardCharsets.UTF_8));
vlt.showCredential();
assertTrue(outputStream.toString().contains("Type"));
assertFalse(vlt.isInt);
}
@Test @Test
void getAsJson() {vlt.getAsJson();} void getAsJson() {vlt.getAsJson();}

Loading…
Cancel
Save