4 Commits

  1. 28
      src/main/java/Vault.java
  2. 47
      src/test/java/VaultTest.java

28
src/main/java/Vault.java

@ -1,6 +1,34 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
public class Vault implements VaultInterface { public class Vault implements VaultInterface {
public boolean config;
InputStream inputS = System.in;
OutputStream outputS = System.out;
private void println(String output) {
try {
outputS.write((output + "\n").getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
e.printStackTrace();
}
}
public void configure(){ public void configure(){
StringBuilder sbcm = new StringBuilder();
Scanner scan = new Scanner(inputS);
config = true;
sbcm.append("Configure:\n");
sbcm.append("- Password length: l\n");
sbcm.append("- Have Capitals: h\n");
sbcm.append("- exit: e\n");
println(sbcm.toString());
} }

47
src/test/java/VaultTest.java

@ -7,8 +7,12 @@ import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import static org.junit.jupiter.api.Assertions.*;
public class VaultTest { public class VaultTest {
//Vault vlt = new Vault();
static Vault vlt; static Vault vlt;
@BeforeAll @BeforeAll
@ -16,11 +20,11 @@ public class VaultTest {
vlt = new Vault(); vlt = new Vault();
} }
/* @BeforeEach
@BeforeEach
void reset() { void reset() {
pm.outputStream = System.out;
pm.inputStream = System.in;
}*/
vlt.outputS = System.out;
vlt.inputS = System.in;
}
@Test @Test
void configure() {vlt.configure();} void configure() {vlt.configure();}
@ -37,4 +41,39 @@ public class VaultTest {
@Test @Test
void loadFromJson() {vlt.loadFromJson();} void loadFromJson() {vlt.loadFromJson();}
@Test
void openConfigureMenu() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = getEmptyStringInputStream();
vlt.outputS = outputStream;
vlt.configure();
assertTrue(outputStream.toString().startsWith("Configure:"));
}
@Test
void exitConfigurationMenu(){
vlt.inputS = new ByteArrayInputStream("e".getBytes(StandardCharsets.UTF_8));
vlt.configure();
assertFalse(vlt.config);
}
@Test
void doNotExitConfigAfterWrongInput() {
vlt.inputS = new ByteArrayInputStream("__\n".getBytes(StandardCharsets.UTF_8));
vlt.configure();
assertTrue(vlt.config);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
vlt.inputS = getEmptyStringInputStream();
vlt.outputS = outputStream;
assertThrowsExactly(NoSuchElementException.class, () -> vlt.configure());
assertTrue(outputStream.toString().startsWith("Configure:"));
}
private ByteArrayInputStream getEmptyStringInputStream() {
return new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8));
}
} }
Loading…
Cancel
Save