[tests] Add test on input contract
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
parent
1454938db8
commit
8f386b4abd
@ -0,0 +1,52 @@
|
|||||||
|
/** gclc-test: InputContractTest
|
||||||
|
* Created on Apr. 6, 2020
|
||||||
|
*/
|
||||||
|
package net.bigeon.gclc.test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.PipedInputStream;
|
||||||
|
import java.io.PipedOutputStream;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import net.bigeon.gclc.manager.EmptyInput;
|
||||||
|
import net.bigeon.gclc.manager.StreamConsoleInput;
|
||||||
|
|
||||||
|
/** @author Emmanuel Bigeon */
|
||||||
|
public class InputContractTest {
|
||||||
|
|
||||||
|
/** Test method for
|
||||||
|
* {@link net.bigeon.gclc.test.InputContract#testInputContract(java.util.function.Supplier)}. */
|
||||||
|
@Test
|
||||||
|
public void testTestInputContract() throws IOException, InterruptedException {
|
||||||
|
final InputContract contract = new InputContract();
|
||||||
|
try (InputStream in = new PipedInputStream(new PipedOutputStream());
|
||||||
|
PrintStream out = new PrintStream("temp.txt")) {
|
||||||
|
contract.testInputContract(
|
||||||
|
() -> new StreamConsoleInput(out, in, StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
contract.testInputContract(() -> EmptyInput.INSTANCE);
|
||||||
|
fail("Empty input does not fit the contract for inputs since it cannot be closed.");
|
||||||
|
} catch (final AssertionError e) {
|
||||||
|
// ok
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
final File f = new File("temp.txt");
|
||||||
|
if (f.exists()) {
|
||||||
|
f.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user