Browse Source

added set special characters function and VaultInterface refactor

feature-vault
fdai6352 3 years ago
parent
commit
dfffc3c84a
  1. 21
      src/main/java/Vault.java
  2. 11
      src/main/java/VaultInterface.java
  3. 20
      src/test/java/VaultTest.java

21
src/main/java/Vault.java

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

11
src/main/java/VaultInterface.java

@ -2,10 +2,9 @@
public interface VaultInterface { public interface VaultInterface {
public void configure();
public void addCredential();
public void showCredential();
public void getAsJson();
public void loadFromJson();
void configure();
void addCredential();
void showCredential();
void getAsJson();
void loadFromJson();
} }

20
src/test/java/VaultTest.java

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

Loading…
Cancel
Save