You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.0 KiB
79 lines
2.0 KiB
import org.junit.jupiter.api.BeforeAll;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.util.NoSuchElementException;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
public class VaultTest {
|
|
|
|
//Vault vlt = new Vault();
|
|
|
|
static Vault vlt;
|
|
|
|
@BeforeAll
|
|
static void init() {
|
|
vlt = new Vault();
|
|
}
|
|
|
|
@BeforeEach
|
|
void reset() {
|
|
vlt.outputS = System.out;
|
|
vlt.inputS = System.in;
|
|
}
|
|
|
|
@Test
|
|
void addCredential() {vlt.addCredential();}
|
|
|
|
@Test
|
|
void showCredential() {vlt.showCredential();}
|
|
|
|
@Test
|
|
void getAsJson() {vlt.getAsJson();}
|
|
|
|
@Test
|
|
void loadFromJson() {vlt.loadFromJson();}
|
|
|
|
@Test
|
|
void setPWLength() {vlt.setPWLength();}
|
|
|
|
@Test
|
|
void openConfigureMenu() {
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
vlt.inputS = new ByteArrayInputStream("__\n".getBytes(StandardCharsets.UTF_8));
|
|
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));
|
|
}
|
|
}
|