Browse Source

refactored if statements to switch cases

feature-credential
fdai6352 2 years ago
parent
commit
d06c407c17
  1. 120
      src/main/java/Vault.java
  2. 5
      src/test/java/VaultTest.java

120
src/main/java/Vault.java

@ -21,10 +21,10 @@ public class Vault implements VaultInterface {
OutputStream outputS = System.out;
private CredentialRepository credentialRepository = new CredentialRepository();
public static void main (String args[]) {
/*public static void main (String args[]) {
Vault vault = new Vault();
vault.credentialMenu();
}
}*/
private void println(String output) {
@ -51,25 +51,36 @@ public class Vault implements VaultInterface {
String input = scan.nextLine();
if (input.equals("e")) {
config = false;
} else if (input.equals("l")) {
println("Set PW length:");
String inputPw = scan.nextLine();
setPWLength(inputPw);
} else if (input.equals("h")) {
println("Should your PW have capitals? Type in yes or no.");
String inputC = scan.nextLine();
setCapital(inputC);
} else if (input.equals("s")){
println("Should you PW have special characters? Type in yes or no.");
String inputS = scan.nextLine();
setSpecialChar(inputS);
} else if (input.equals("n")) {
println("Should you PW have numbers? Type in yes or no.");
String inputN = scan.nextLine();
setNumbers(inputN);
switch(input) {
case "e":
config = false;
break;
case "l":
println("Set PW length:");
String inputPw = scan.nextLine();
setPWLength(inputPw);
break;
case "h":
println("Should your PW have capitals? Type in yes or no.");
String inputC = scan.nextLine();
setCapital(inputC);
break;
case "s":
println("Should you PW have special characters? Type in yes or no.");
String inputS = scan.nextLine();
setSpecialChar(inputS);
break;
case "n":
println("Should you PW have numbers? Type in yes or no.");
String inputN = scan.nextLine();
setNumbers(inputN);
break;
}
}
public void setPWLength(String pwLength) {
@ -157,40 +168,41 @@ public class Vault implements VaultInterface {
String input = scan.nextLine();
if (input.equals("e")) {
credentialM = false;
}
if (input.equals("a")) {
println("Type in username");
userName = scan.nextLine();
println("Type in password");
password = scan.nextLine();
addCredential(userName, password);
}
if (input.equals("c")) {
println("Type in ID or username");
String str = scan.nextLine();
showCredential(str);
} else if (input.equals("l")) {
println("Type ID to select credential:");
newID = Integer.parseInt(scan.nextLine());
println("-change username: u\n-change password: p");
input = scan.nextLine();
if (input.equals("u")) {
decision = true;
}else{
decision = false;
}
println("Type new:");
newString = scan.nextLine();
//editCredential(newID, newString, decision);
switch(input) {
case "e":
credentialM = false;
break;
case "a":
println("Type in username");
userName = scan.nextLine();
println("Type in password");
password = scan.nextLine();
addCredential(userName, password);
break;
case "c":
println("Type in ID or username");
String str = scan.nextLine();
showCredential(str);
break;
case "l":
println("Type ID to select credential:");
newID = Integer.parseInt(scan.nextLine());
println("-change username: u\n-change password: p");
input = scan.nextLine();
if (!input.equals("u")) {
decision = false;
}
println("Type new:");
newString = scan.nextLine();
//editCredential(newID, newString, decision);
break;
}
}
}

5
src/test/java/VaultTest.java

@ -1,7 +1,6 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@ -12,8 +11,6 @@ import static org.junit.jupiter.api.Assertions.*;
public class VaultTest {
//Vault vlt = new Vault();
static Vault vlt;
@BeforeAll
@ -74,7 +71,7 @@ public class VaultTest {
vlt.credentialMenu();
assertTrue(outputStream.toString().contains("Type"));
assertEquals(1,vlt.newID);
assertEquals(true,vlt.decision);
assertTrue(vlt.decision);
assertEquals("peter",vlt.newString);
}

Loading…
Cancel
Save