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

2
src/main/java/VaultInterface.java

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

19
src/test/java/VaultTest.java

@ -41,18 +41,15 @@ public class VaultTest {
assertFalse(vlt.credentialM); assertFalse(vlt.credentialM);
} }
@Test
/* @Test
void openAddCredentialMenuItem() { void openAddCredentialMenuItem() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 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.outputS = outputStream;
vlt.credentialMenu(); 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 @Test
void openShowCredentialMenuItem() { void openShowCredentialMenuItem() {
@ -80,7 +77,7 @@ public class VaultTest {
}*/ }*/
/*@Test
@Test
void addCredentialTest() { void addCredentialTest() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.outputS = outputStream; vlt.outputS = outputStream;
@ -93,12 +90,12 @@ 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.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.inputS = new ByteArrayInputStream("l\npeter".getBytes(StandardCharsets.UTF_8));
vlt.credentialMenu(); vlt.credentialMenu();

Loading…
Cancel
Save