Browse Source

implemented set numbers menu item and test refactor

feature-vault
fdai6352 3 years ago
parent
commit
c9968722c8
  1. 10
      src/main/java/Vault.java
  2. 17
      src/test/java/VaultTest.java

10
src/main/java/Vault.java

@ -53,6 +53,10 @@ public class Vault implements VaultInterface {
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")) {
println("Should you PW have numbers? Type in yes or no.");
String inputN = scan.nextLine();
setNumbers(input);
} }
} }
@ -113,11 +117,7 @@ public class Vault implements VaultInterface {
} }
} }
public void SetNumbers() {
println("Should you PW have numbers? Type in yes or no.");
Scanner scan = new Scanner(inputS);
String input = scan.nextLine();
public void setNumbers(String input) {
if(input.equals("yes")){ if(input.equals("yes")){
hasNumbers = true; hasNumbers = true;

17
src/test/java/VaultTest.java

@ -148,22 +148,27 @@ public class VaultTest {
assertTrue(outputStream.toString().contains("don´t")); assertTrue(outputStream.toString().contains("don´t"));
} }
@Test
void openSetNumbersMenuItem() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = new ByteArrayInputStream("h\nyes".getBytes(StandardCharsets.UTF_8));
vlt.outputS = outputStream;
vlt.configure();
assertTrue(vlt.hasNumbers = true);
}
@Test @Test
void setNumbersTest() { void setNumbersTest() {
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.SetNumbers();
vlt.setNumbers("yes");
assertTrue(outputStream.toString().startsWith("Should"));
assertTrue(vlt.hasNumbers = true); assertTrue(vlt.hasNumbers = true);
assertTrue(outputStream.toString().contains("contain")); assertTrue(outputStream.toString().contains("contain"));
vlt.inputS = new ByteArrayInputStream("no\n".getBytes(StandardCharsets.UTF_8));
vlt.outputS = outputStream; vlt.outputS = outputStream;
vlt.SetNumbers();
vlt.setNumbers("no");
assertTrue(outputStream.toString().startsWith("Should"));
assertFalse(vlt.hasNumbers = false); assertFalse(vlt.hasNumbers = false);
assertTrue(outputStream.toString().contains("don´t")); assertTrue(outputStream.toString().contains("don´t"));
} }

Loading…
Cancel
Save