Changed prompt interruption contract

Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
2018-12-01 10:54:51 -05:00
parent c4bbfd8434
commit c206b5b22c
5 changed files with 86 additions and 18 deletions

View File

@@ -8,18 +8,19 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.function.Supplier;
import net.bigeon.gclc.manager.ConsoleInput;
import net.bigeon.test.junitmt.FunctionalTestRunnable;
import net.bigeon.test.junitmt.TestFunction;
import net.bigeon.test.junitmt.ThreadTest;
/**
* @author Emmanuel Bigeon
*
*/
/** @author Emmanuel Bigeon */
public final class InputContract {
public void testInputContract(final Supplier<ConsoleInput> inputs)
throws IOException {
throws IOException, InterruptedException {
// Test close contract
final ConsoleInput input = inputs.get();
assertFalse("An input should not initially be closed", input.isClosed());
@@ -33,5 +34,29 @@ public final class InputContract {
} catch (final IOException e) {
// ok
}
// Test interruption contract
final ConsoleInput input2 = inputs.get();
final FunctionalTestRunnable prompting = new FunctionalTestRunnable(
new TestFunction() {
@Override
public void apply() throws Exception {
try {
input2.prompt();
fail("Interrupted prompt should throw INterruptedIOException");
} catch (final InterruptedIOException e) {
// ok
}
}
});
final Thread th = new Thread(prompting);
th.start();
// while (!input2.isPrompting()) {
th.join(200);
//
// }
input2.interruptPrompt();
ThreadTest.assertRuns(th, prompting);
}
}