Browse Source

added Set PWLength Funtionality

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

8
src/main/java/Vault.java

@ -7,6 +7,7 @@ import java.util.Scanner;
public class Vault implements VaultInterface { public class Vault implements VaultInterface {
public boolean config; public boolean config;
public int PWLength;
InputStream inputS = System.in; InputStream inputS = System.in;
OutputStream outputS = System.out; OutputStream outputS = System.out;
@ -40,6 +41,13 @@ public class Vault implements VaultInterface {
public void setPWLength(){ public void setPWLength(){
println("Set PW length:"); println("Set PW length:");
Scanner scan = new Scanner(inputS);
String input = scan.nextLine();
PWLength = Integer.parseInt(input);
println("\nNew PWlength is now: ");
} }

12
src/test/java/VaultTest.java

@ -72,11 +72,23 @@ public class VaultTest {
@Test @Test
void openSetPWLength() { void openSetPWLength() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = new ByteArrayInputStream("12".getBytes(StandardCharsets.UTF_8));
vlt.outputS = outputStream; vlt.outputS = outputStream;
vlt.setPWLength(); vlt.setPWLength();
assertTrue(outputStream.toString().startsWith("Set")); assertTrue(outputStream.toString().startsWith("Set"));
} }
@Test
void setPWLength() {
vlt.inputS = new ByteArrayInputStream("7\n".getBytes(StandardCharsets.UTF_8));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.outputS = outputStream;
vlt.setPWLength();
assertEquals(7, vlt.PWLength);
assertTrue(outputStream.toString().contains("now:"));
}
private ByteArrayInputStream getEmptyStringInputStream() { private ByteArrayInputStream getEmptyStringInputStream() {
return new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)); return new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8));
} }

Loading…
Cancel
Save