Browse Source

implemented setPWLength in configure menu and refactor

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

12
src/main/java/Vault.java

@ -39,20 +39,20 @@ public class Vault implements VaultInterface {
if (input.equals("e")) { if (input.equals("e")) {
config = false; config = false;
}else if (!input.equals("l")|!input.equals("l")|!input.equals("l")) {
}else if (input.equals("l")) {
String inputpw = scan.nextLine();
setPWLength(inputpw);
}else if (!input.equals("l")|!input.equals("e")|!input.equals("h")) {
println("Please enter valid key."); println("Please enter valid key.");
} }
} }
public void setPWLength(){
public void setPWLength(String pwLength){
println("Set PW length:"); println("Set PW length:");
Scanner scan = new Scanner(inputS);
String input = scan.nextLine();
try { try {
PWLength = Integer.parseInt(input);
PWLength = Integer.parseInt(pwLength);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
println("Please Enter Valid Number."); println("Please Enter Valid Number.");
} }

24
src/test/java/VaultTest.java

@ -90,38 +90,24 @@ public class VaultTest {
@Test @Test
void openSetPWLength() {
void openSetPWLengthMenuItem() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = new ByteArrayInputStream("12".getBytes(StandardCharsets.UTF_8));
vlt.inputS = new ByteArrayInputStream("l\n7".getBytes(StandardCharsets.UTF_8));
vlt.outputS = outputStream; vlt.outputS = outputStream;
vlt.setPWLength();
assertTrue(outputStream.toString().startsWith("Set"));
vlt.configure();
assertEquals(7, vlt.PWLength);
} }
@Test @Test
void setPWLength() { void setPWLength() {
vlt.inputS = new ByteArrayInputStream("7\n".getBytes(StandardCharsets.UTF_8));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.outputS = outputStream; vlt.outputS = outputStream;
vlt.setPWLength();
vlt.setPWLength("7");
assertEquals(7, vlt.PWLength); assertEquals(7, vlt.PWLength);
assertTrue(outputStream.toString().contains("now:")); 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"));
}
@Test @Test
void setCapital() { void setCapital() {
vlt.inputS = new ByteArrayInputStream("yes\n".getBytes(StandardCharsets.UTF_8)); vlt.inputS = new ByteArrayInputStream("yes\n".getBytes(StandardCharsets.UTF_8));

Loading…
Cancel
Save