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.
94 lines
2.7 KiB
94 lines
2.7 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.*;
|
|
|
|
|
|
class PasswordManagerTest {
|
|
|
|
static PasswordManager pm;
|
|
|
|
@BeforeAll
|
|
static void init() {
|
|
pm = new PasswordManager();
|
|
}
|
|
|
|
@BeforeEach
|
|
void reset() {
|
|
pm.outputStream = System.out;
|
|
pm.inputStream = System.in;
|
|
}
|
|
|
|
@Test
|
|
void constructor() {
|
|
assertInstanceOf(PasswordManager.class, pm);
|
|
}
|
|
|
|
@Test
|
|
void listVaults() {
|
|
pm.listVaults();
|
|
}
|
|
|
|
@Test
|
|
void openVault() {
|
|
pm.openVault();
|
|
}
|
|
|
|
@Test
|
|
void menuNavigationListVaults() {
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
pm.inputStream = new ByteArrayInputStream("l\n".getBytes(StandardCharsets.UTF_8));
|
|
pm.outputStream = outputStream;
|
|
pm.showMenu();
|
|
assertTrue(outputStream.toString().endsWith("Vaults:\n"));
|
|
}
|
|
|
|
@Test
|
|
void menuNavigationOpenVault() {
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
pm.inputStream = new ByteArrayInputStream("v 0\n".getBytes(StandardCharsets.UTF_8));
|
|
pm.outputStream = outputStream;
|
|
pm.showMenu();
|
|
assertTrue(outputStream.toString().endsWith("-- vaults not implemented yet\n"));
|
|
}
|
|
|
|
@Test
|
|
void showMenu() {
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
pm.inputStream = getEmptyStringInputStream();
|
|
pm.outputStream = outputStream;
|
|
assertThrowsExactly(NoSuchElementException.class, () -> pm.showMenu());
|
|
assertTrue(outputStream.toString().startsWith("\nciip Gruppe 8"));
|
|
}
|
|
|
|
@Test
|
|
void exitMenu() {
|
|
pm.inputStream = new ByteArrayInputStream("e\n".getBytes(StandardCharsets.UTF_8));
|
|
pm.showMenu();
|
|
assertFalse(pm.running);
|
|
}
|
|
|
|
@Test
|
|
void doNotExitMenuAfterWrongInput() {
|
|
pm.inputStream = new ByteArrayInputStream("__\n".getBytes(StandardCharsets.UTF_8));
|
|
pm.showMenu();
|
|
assertTrue(pm.running);
|
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
pm.inputStream = getEmptyStringInputStream();
|
|
pm.outputStream = outputStream;
|
|
|
|
assertThrowsExactly(NoSuchElementException.class, () -> pm.showMenu());
|
|
assertTrue(outputStream.toString().startsWith("\nciip Gruppe 8"));
|
|
}
|
|
|
|
private ByteArrayInputStream getEmptyStringInputStream() {
|
|
return new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8));
|
|
}
|
|
}
|