Browse Source

refactored if statements to switch cases

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

46
src/main/java/Vault.java

@ -21,10 +21,10 @@ public class Vault implements VaultInterface {
OutputStream outputS = System.out; OutputStream outputS = System.out;
private CredentialRepository credentialRepository = new CredentialRepository(); private CredentialRepository credentialRepository = new CredentialRepository();
public static void main (String args[]) {
/*public static void main (String args[]) {
Vault vault = new Vault(); Vault vault = new Vault();
vault.credentialMenu(); vault.credentialMenu();
}
}*/
private void println(String output) { private void println(String output) {
@ -51,25 +51,36 @@ public class Vault implements VaultInterface {
String input = scan.nextLine(); String input = scan.nextLine();
if (input.equals("e")) {
switch(input) {
case "e":
config = false; config = false;
} else if (input.equals("l")) {
break;
case "l":
println("Set PW length:"); println("Set PW length:");
String inputPw = scan.nextLine(); String inputPw = scan.nextLine();
setPWLength(inputPw); setPWLength(inputPw);
} else if (input.equals("h")) {
break;
case "h":
println("Should your PW have capitals? Type in yes or no."); println("Should your PW have capitals? Type in yes or no.");
String inputC = scan.nextLine(); String inputC = scan.nextLine();
setCapital(inputC); setCapital(inputC);
} else if (input.equals("s")){
break;
case "s":
println("Should you PW have special characters? Type in yes or no."); println("Should you PW have special characters? Type in yes or no.");
String inputS = scan.nextLine(); String inputS = scan.nextLine();
setSpecialChar(inputS); setSpecialChar(inputS);
} else if (input.equals("n")) {
break;
case "n":
println("Should you PW have numbers? Type in yes or no."); println("Should you PW have numbers? Type in yes or no.");
String inputN = scan.nextLine(); String inputN = scan.nextLine();
setNumbers(inputN); setNumbers(inputN);
break;
} }
} }
public void setPWLength(String pwLength) { public void setPWLength(String pwLength) {
@ -157,40 +168,41 @@ public class Vault implements VaultInterface {
String input = scan.nextLine(); String input = scan.nextLine();
if (input.equals("e")) {
switch(input) {
case "e":
credentialM = false; credentialM = false;
}
break;
if (input.equals("a")) {
case "a":
println("Type in username"); println("Type in username");
userName = scan.nextLine(); userName = scan.nextLine();
println("Type in password"); println("Type in password");
password = scan.nextLine(); password = scan.nextLine();
addCredential(userName, password); addCredential(userName, password);
}
break;
if (input.equals("c")) {
case "c":
println("Type in ID or username"); println("Type in ID or username");
String str = scan.nextLine(); String str = scan.nextLine();
showCredential(str); showCredential(str);
break;
} else if (input.equals("l")) {
case "l":
println("Type ID to select credential:"); println("Type ID to select credential:");
newID = Integer.parseInt(scan.nextLine()); newID = Integer.parseInt(scan.nextLine());
println("-change username: u\n-change password: p"); println("-change username: u\n-change password: p");
input = scan.nextLine(); input = scan.nextLine();
if (input.equals("u")) {
decision = true;
}else{
if (!input.equals("u")) {
decision = false; decision = false;
} }
println("Type new:"); println("Type new:");
newString = scan.nextLine(); newString = scan.nextLine();
//editCredential(newID, newString, decision); //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.BeforeAll;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -12,8 +11,6 @@ import static org.junit.jupiter.api.Assertions.*;
public class VaultTest { public class VaultTest {
//Vault vlt = new Vault();
static Vault vlt; static Vault vlt;
@BeforeAll @BeforeAll
@ -74,7 +71,7 @@ public class VaultTest {
vlt.credentialMenu(); vlt.credentialMenu();
assertTrue(outputStream.toString().contains("Type")); assertTrue(outputStream.toString().contains("Type"));
assertEquals(1,vlt.newID); assertEquals(1,vlt.newID);
assertEquals(true,vlt.decision);
assertTrue(vlt.decision);
assertEquals("peter",vlt.newString); assertEquals("peter",vlt.newString);
} }

Loading…
Cancel
Save