Browse Source

refactored addCredential for better compatibility

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

20
src/main/java/Vault.java

@ -94,7 +94,13 @@ public class Vault implements VaultInterface {
}
public void addCredential(String userName, String password){
public void addCredential(){
Scanner scan = new Scanner(inputS);
println("Type in username");
userName = scan.nextLine();
println("Type in password");
password = scan.nextLine();
credentialRepository.createNewCredential(userName, password);
}
@ -182,12 +188,8 @@ public class Vault implements VaultInterface {
break;
case "a":
println("Type in username");
userName = scan.nextLine();
println("Type in password");
password = scan.nextLine();
addCredential(userName, password);
println("Add credential:");
addCredential();
break;
case "c":
@ -204,8 +206,8 @@ public class Vault implements VaultInterface {
input = scan.nextLine();
if (!input.equals("u")) {
decision = false;
if (input.equals("u")) {
decision = true;
}
println("Type new:");
newString = scan.nextLine();

2
src/main/java/VaultInterface.java

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

19
src/test/java/VaultTest.java

@ -41,18 +41,15 @@ public class VaultTest {
assertFalse(vlt.credentialM);
}
@Test
/* @Test
void openAddCredentialMenuItem() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = new ByteArrayInputStream("a\npeter\npassword".getBytes(StandardCharsets.UTF_8));
vlt.inputS = new ByteArrayInputStream("a".getBytes(StandardCharsets.UTF_8));
vlt.outputS = outputStream;
vlt.credentialMenu();
assertTrue(outputStream.toString().contains("username"));
assertEquals("peter", vlt.userName);
assertTrue(outputStream.toString().contains("password"));
assertEquals("password",vlt.password);
}
assertTrue(outputStream.toString().contains("Add"));
}*/
@Test
void openShowCredentialMenuItem() {
@ -80,7 +77,7 @@ public class VaultTest {
}*/
/*@Test
@Test
void addCredentialTest() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.outputS = outputStream;
@ -93,12 +90,12 @@ public class VaultTest {
assertEquals("password",vlt.password);
}
@Test
/* @Test
void showCredentialTest() {
vlt.inputS = new ByteArrayInputStream("l\n1".getBytes(StandardCharsets.UTF_8));
vlt.credentialMenu();
vlt.showCredential();credential();
assertTrue(vlt.isInt);
assertTrue(outputStream.toString().contains("username"));
vlt.inputS = new ByteArrayInputStream("l\npeter".getBytes(StandardCharsets.UTF_8));
vlt.credentialMenu();

Loading…
Cancel
Save