Browse Source

implemented set special char menu item and test refactor

feature-vault
fdai6352 3 years ago
parent
commit
05988f788b
  1. 14
      src/main/java/Vault.java
  2. 18
      src/test/java/VaultTest.java

14
src/main/java/Vault.java

@ -31,6 +31,8 @@ public class Vault implements VaultInterface {
sbcm.append("Configure:\n"); sbcm.append("Configure:\n");
sbcm.append("- Password length: l\n"); sbcm.append("- Password length: l\n");
sbcm.append("- Have Capitals: h\n"); sbcm.append("- Have Capitals: h\n");
sbcm.append("- Have Special Characters: s\n");
sbcm.append("- Have Numbers: n\n");
sbcm.append("- exit: e\n"); sbcm.append("- exit: e\n");
println(sbcm.toString()); println(sbcm.toString());
@ -46,7 +48,11 @@ public class Vault implements VaultInterface {
} else if (input.equals("h")) { } else if (input.equals("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();
setPWLength(inputC);
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);
} }
} }
@ -96,11 +102,7 @@ public class Vault implements VaultInterface {
} }
public void setSpecialChar() {
println("Should you PW have special characters? Type in yes or no.");
Scanner scan = new Scanner(inputS);
String input = scan.nextLine();
public void setSpecialChar(String input) {
if(input.equals("yes")){ if(input.equals("yes")){
hasSpecialChars = true; hasSpecialChars = true;

18
src/test/java/VaultTest.java

@ -124,22 +124,26 @@ public class VaultTest {
assertTrue(outputStream.toString().contains("don´t")); assertTrue(outputStream.toString().contains("don´t"));
} }
@Test
void openSetSpecialCharsMenuItem() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = new ByteArrayInputStream("h\nyes".getBytes(StandardCharsets.UTF_8));
vlt.outputS = outputStream;
vlt.configure();
assertTrue(vlt.hasSpecialChars = true);
}
@Test @Test
void setSpecialCharTest() { void setSpecialCharTest() {
vlt.inputS = new ByteArrayInputStream("yes\n".getBytes(StandardCharsets.UTF_8));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.outputS = outputStream; vlt.outputS = outputStream;
vlt.setSpecialChar();
vlt.setSpecialChar("yes");
assertTrue(outputStream.toString().startsWith("Should"));
assertTrue(vlt.hasSpecialChars = true); assertTrue(vlt.hasSpecialChars = true);
assertTrue(outputStream.toString().contains("contain"));
vlt.inputS = new ByteArrayInputStream("no\n".getBytes(StandardCharsets.UTF_8));
vlt.outputS = outputStream; vlt.outputS = outputStream;
vlt.setSpecialChar();
vlt.setSpecialChar("no");
assertTrue(outputStream.toString().startsWith("Should"));
assertFalse(vlt.hasSpecialChars = false); assertFalse(vlt.hasSpecialChars = false);
assertTrue(outputStream.toString().contains("don´t")); assertTrue(outputStream.toString().contains("don´t"));
} }

Loading…
Cancel
Save