|
|
@ -1,7 +1,9 @@ |
|
|
|
import org.junit.jupiter.api.BeforeAll; |
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
|
|
|
import java.io.*; |
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.util.NoSuchElementException; |
|
|
|
|
|
|
@ -17,6 +19,12 @@ class PasswordManagerTest { |
|
|
|
pm = new PasswordManager(); |
|
|
|
} |
|
|
|
|
|
|
|
@BeforeEach |
|
|
|
void reset() { |
|
|
|
pm.outputStream = System.out; |
|
|
|
pm.inputStream = System.in; |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void constructor() { |
|
|
|
assertInstanceOf(PasswordManager.class, pm); |
|
|
@ -32,26 +40,42 @@ class PasswordManagerTest { |
|
|
|
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 showMenu() { |
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
|
|
|
assertThrowsExactly(NoSuchElementException.class, () -> pm.showMenu(getEmptyStringInputStream(), outputStream)); |
|
|
|
pm.inputStream = getEmptyStringInputStream(); |
|
|
|
pm.outputStream = outputStream; |
|
|
|
assertThrowsExactly(NoSuchElementException.class, () -> pm.showMenu()); |
|
|
|
assertTrue(outputStream.toString().startsWith("ciip Gruppe 8")); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void exitMenu() { |
|
|
|
pm.showMenu(new ByteArrayInputStream("e\n".getBytes(StandardCharsets.UTF_8)), System.out); |
|
|
|
pm.inputStream = new ByteArrayInputStream("e\n".getBytes(StandardCharsets.UTF_8)); |
|
|
|
pm.showMenu(); |
|
|
|
assertFalse(pm.running); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void doNotExitMenuAfterWrongInput() { |
|
|
|
pm.showMenu(new ByteArrayInputStream("__\n".getBytes(StandardCharsets.UTF_8)), System.out); |
|
|
|
pm.inputStream = new ByteArrayInputStream("__\n".getBytes(StandardCharsets.UTF_8)); |
|
|
|
pm.showMenu(); |
|
|
|
assertTrue(pm.running); |
|
|
|
|
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
|
|
|
assertThrowsExactly(NoSuchElementException.class, () -> pm.showMenu(getEmptyStringInputStream(), outputStream)); |
|
|
|
pm.inputStream = getEmptyStringInputStream(); |
|
|
|
pm.outputStream = outputStream; |
|
|
|
|
|
|
|
assertThrowsExactly(NoSuchElementException.class, () -> pm.showMenu()); |
|
|
|
assertTrue(outputStream.toString().startsWith("ciip Gruppe 8")); |
|
|
|
} |
|
|
|
|
|
|
|