Browse Source

added Set Capital function

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

15
src/main/java/Vault.java

@ -8,6 +8,7 @@ public class Vault implements VaultInterface {
public boolean config;
public int PWLength;
public boolean haveCapitals = false;
InputStream inputS = System.in;
OutputStream outputS = System.out;
@ -73,4 +74,18 @@ public class Vault implements VaultInterface {
}
public void setCapital() {
println("Should you PW have Capitals? Type in yes or no.");
Scanner scan = new Scanner(inputS);
String input = scan.nextLine();
if(input.equals("yes")){
haveCapitals = true;
println("Your PWs contain now capitals.");
}else if(input.equals("no")){
haveCapitals = false;
println("Your PWs don´t have capitals anymore.");
}
}
}

20
src/test/java/VaultTest.java

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

Loading…
Cancel
Save