5 Commits

  1. 40
      src/main/java/Vault.java
  2. 53
      src/test/java/VaultTest.java

40
src/main/java/Vault.java

@ -7,6 +7,8 @@ import java.util.Scanner;
public class Vault implements VaultInterface { public class Vault implements VaultInterface {
public boolean config; public boolean config;
public int PWLength;
public boolean haveCapitals = false;
InputStream inputS = System.in; InputStream inputS = System.in;
OutputStream outputS = System.out; OutputStream outputS = System.out;
@ -30,8 +32,32 @@ public class Vault implements VaultInterface {
println(sbcm.toString()); println(sbcm.toString());
String input = scan.nextLine();
if (input.equals("e")) {
config = false;
}
}
public void setPWLength(){
println("Set PW length:");
Scanner scan = new Scanner(inputS);
String input = scan.nextLine();
try {
PWLength = Integer.parseInt(input);
} catch (NumberFormatException e) {
println("Please Enter Valid Number.");
} }
println("\nNew PWlength is now: ");
}
public void addCredential(){ public void addCredential(){
} }
@ -48,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.");
}
}
} }

53
src/test/java/VaultTest.java

@ -1,6 +1,7 @@
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -68,10 +69,58 @@ public class VaultTest {
assertTrue(outputStream.toString().startsWith("Configure:")); assertTrue(outputStream.toString().startsWith("Configure:"));
} }
// @Test
// void
@Test
void openSetPWLength() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = new ByteArrayInputStream("12".getBytes(StandardCharsets.UTF_8));
vlt.outputS = outputStream;
vlt.setPWLength();
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:"));
}
@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
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() { private ByteArrayInputStream getEmptyStringInputStream() {
return new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)); return new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8));

Loading…
Cancel
Save