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.

61 lines
1.6 KiB

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.io.*;
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();
}
@Test
void constructor() {
assertInstanceOf(PasswordManager.class, pm);
}
@Test
void listVaults() {
pm.listVaults();
}
@Test
void openVault() {
pm.openVault();
}
@Test
void showMenu() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
assertThrowsExactly(NoSuchElementException.class, () -> pm.showMenu(getEmptyStringInputStream(), outputStream));
assertTrue(outputStream.toString().startsWith("ciip Gruppe 8"));
}
@Test
void exitMenu() {
pm.showMenu(new ByteArrayInputStream("e\n".getBytes(StandardCharsets.UTF_8)), System.out);
assertFalse(pm.running);
}
@Test
void doNotExitMenuAfterWrongInput() {
pm.showMenu(new ByteArrayInputStream("__\n".getBytes(StandardCharsets.UTF_8)), System.out);
assertTrue(pm.running);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
assertThrowsExactly(NoSuchElementException.class, () -> pm.showMenu(getEmptyStringInputStream(), outputStream));
assertTrue(outputStream.toString().startsWith("ciip Gruppe 8"));
}
private ByteArrayInputStream getEmptyStringInputStream() {
return new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8));
}
}