Browse Source

Set PWLength Functionality, proved against wrong input

feature-vault
fdai6352 3 years ago
parent
commit
087e2d6b60
  1. 8
      src/main/java/Vault.java
  2. 13
      src/test/java/VaultTest.java

8
src/main/java/Vault.java

@ -45,7 +45,13 @@ public class Vault implements VaultInterface {
Scanner scan = new Scanner(inputS);
String input = scan.nextLine();
PWLength = Integer.parseInt(input);
try {
PWLength = Integer.parseInt(input);
} catch (NumberFormatException e) {
println("Please Enter Valid Number.");
}
println("\nNew PWlength is now: ");
}

13
src/test/java/VaultTest.java

@ -89,6 +89,19 @@ public class VaultTest {
assertTrue(outputStream.toString().contains("now:"));
}
@Test
void setPWLengthWrongInput() {
vlt.inputS = new ByteArrayInputStream("T\n".getBytes(StandardCharsets.UTF_8));
vlt.setPWLength();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = getEmptyStringInputStream();
vlt.outputS = outputStream;
assertThrowsExactly(NoSuchElementException.class, () -> vlt.setPWLength());
assertTrue(outputStream.toString().startsWith("Set"));
}
private ByteArrayInputStream getEmptyStringInputStream() {
return new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8));
}

Loading…
Cancel
Save