Browse Source

added set numbers function

feature-vault
fdai6352 3 years ago
parent
commit
db0423a18c
  1. 16
      src/main/java/Vault.java
  2. 20
      src/test/java/VaultTest.java

16
src/main/java/Vault.java

@ -10,6 +10,7 @@ public class Vault implements VaultInterface {
public int PWLength;
public boolean haveCapitals;
public boolean hasSpecialChars;
public boolean hasNumbers;
InputStream inputS = System.in;
OutputStream outputS = System.out;
@ -105,4 +106,19 @@ public class Vault implements VaultInterface {
println("Your PWs don´t have special characters anymore.");
}
}
public void SetNumbers() {
println("Should you PW have numbers? Type in yes or no.");
Scanner scan = new Scanner(inputS);
String input = scan.nextLine();
if(input.equals("yes")){
hasNumbers = true;
println("Your PWs contains now numbers.");
}else if(input.equals("no")){
hasNumbers = false;
println("Your PWs don´t have numbers anymore.");
}
}
}

20
src/test/java/VaultTest.java

@ -142,6 +142,26 @@ public class VaultTest {
assertTrue(outputStream.toString().contains("don´t"));
}
@Test
void setNumbersTest() {
vlt.inputS = new ByteArrayInputStream("yes\n".getBytes(StandardCharsets.UTF_8));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.outputS = outputStream;
vlt.SetNumbers();
assertTrue(outputStream.toString().startsWith("Should"));
assertTrue(vlt.hasNumbers = true);
assertTrue(outputStream.toString().contains("contain"));
vlt.inputS = new ByteArrayInputStream("no\n".getBytes(StandardCharsets.UTF_8));
vlt.outputS = outputStream;
vlt.SetNumbers();
assertTrue(outputStream.toString().startsWith("Should"));
assertFalse(vlt.hasNumbers = false);
assertTrue(outputStream.toString().contains("don´t"));
}
private ByteArrayInputStream getEmptyStringInputStream() {
return new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8));
}

Loading…
Cancel
Save