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