|
|
@ -7,8 +7,12 @@ 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 |
|
|
@ -16,11 +20,11 @@ public class VaultTest { |
|
|
|
vlt = new Vault(); |
|
|
|
} |
|
|
|
|
|
|
|
/* @BeforeEach |
|
|
|
@BeforeEach |
|
|
|
void reset() { |
|
|
|
pm.outputStream = System.out; |
|
|
|
pm.inputStream = System.in; |
|
|
|
}*/ |
|
|
|
vlt.outputS = System.out; |
|
|
|
vlt.inputS = System.in; |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void configure() {vlt.configure();} |
|
|
@ -37,4 +41,39 @@ public class VaultTest { |
|
|
|
@Test |
|
|
|
void loadFromJson() {vlt.loadFromJson();} |
|
|
|
|
|
|
|
@Test |
|
|
|
void openConfigureMenu() { |
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
|
|
|
vlt.inputS = getEmptyStringInputStream(); |
|
|
|
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)); |
|
|
|
} |
|
|
|
} |