Browse Source

refactored add credential Method and Test

feature-credential
fdai6352 3 years ago
parent
commit
f014afbf83
  1. 2
      src/main/java/CredentialRepository.java
  2. 33
      src/main/java/Vault.java
  3. 2
      src/main/java/VaultInterface.java
  4. 12
      src/test/java/VaultTest.java

2
src/main/java/CredentialRepository.java

@ -106,7 +106,7 @@ public class CredentialRepository implements CredentialRepositoryInterface{
return -1;
}
*/
private int getListSize()
public int getListSize()
{
return this.credentials.size();
}

33
src/main/java/Vault.java

@ -17,6 +17,13 @@ public class Vault implements VaultInterface {
public boolean isInt = false;
InputStream inputS = System.in;
OutputStream outputS = System.out;
private CredentialRepository credentialRepository = new CredentialRepository();
public static void main (String args[]) {
Vault vault = new Vault();
vault.credentialMenu();
}
private void println(String output) {
try {
@ -74,15 +81,8 @@ public class Vault implements VaultInterface {
}
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 addCredential(String userName, String password){
credentialRepository.createNewCredential(userName, password);
}
public void showCredential(){
@ -93,10 +93,10 @@ public class Vault implements VaultInterface {
if(str.matches("[0-9]+")) {
isInt = true;
//getCredentialsViaId(Integer.parseInt(str));
credentialRepository.getCredentialsViaId(Integer.parseInt(str));
} else {
isInt = false;
//getCredentialsViaName(str);
credentialRepository.getCredentialsViaName(str);
}
}
@ -158,12 +158,19 @@ public class Vault implements VaultInterface {
String input = scan.nextLine();
if (input.equals("e")) {
credentialM = false;
} else if (input.equals("a")) {
println("Type username:");
println("Type in username");
userName = scan.nextLine();
println("Type in password");
password = scan.nextLine();
addCredential(userName, password);
} else if (input.equals("c")) {
println("Type username or ID to show credential:");
//println("Type username or ID to show credential:");
showCredential();
} else if (input.equals("l")) {
println("Type username or ID to select credential:");
}

2
src/main/java/VaultInterface.java

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

12
src/test/java/VaultTest.java

@ -47,13 +47,17 @@ public class VaultTest {
@Test
void openAddCredentialMenuItem() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = new ByteArrayInputStream("a".getBytes(StandardCharsets.UTF_8));
vlt.inputS = new ByteArrayInputStream("a\npeter\npassword".getBytes(StandardCharsets.UTF_8));
vlt.outputS = outputStream;
vlt.credentialMenu();
assertTrue(outputStream.toString().contains("Type"));
assertTrue(outputStream.toString().contains("username"));
assertEquals("peter", vlt.userName);
assertTrue(outputStream.toString().contains("password"));
assertEquals("password",vlt.password);
}
@Test
/*@Test
void openShowCredentialMenuItem() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = new ByteArrayInputStream("c".getBytes(StandardCharsets.UTF_8));
@ -82,7 +86,7 @@ public class VaultTest {
assertEquals("peter", vlt.userName);
assertTrue(outputStream.toString().contains("password"));
assertEquals("password",vlt.password);
}
}*/
@Test
void showCredentialTest() {

Loading…
Cancel
Save