88import java .io .UncheckedIOException ;
99import java .nio .charset .StandardCharsets ;
1010import java .util .Optional ;
11+ import java .util .concurrent .TimeoutException ;
1112
1213import org .junit .jupiter .api .Assertions ;
1314import org .opentest4j .AssertionFailedError ;
1718import io .github .netmikey .testprocesses .TestProcessDefinitionBy ;
1819import io .github .netmikey .testprocesses .TestProcessState ;
1920import io .github .netmikey .testprocesses .TestProcessesRegistry ;
21+ import io .github .netmikey .testprocesses .eventdetector .LogPatternEventDetector ;
2022
2123/**
2224 * Utility method for asserting and interacting with those test processes
2325 * specifically created for these framework-tests.
2426 */
2527public class TestHelper {
2628
29+ private static final TestProcessDefinitionBy <EchoTestProcess > ECHO_TEST_PROCESS = TestProcessDefinitionBy
30+ .clazz (EchoTestProcess .class );
31+
2732 /**
2833 * Sends a line of test to the {@link EchoTestProcess} currently running in
2934 * the specified registry.
@@ -35,7 +40,7 @@ public class TestHelper {
3540 */
3641 public static void sendToEchoProcess (TestProcessesRegistry registry , String line ) {
3742 Optional <RunningTestProcess <EchoTestProcess >> runningProcess = registry
38- .retrieveRunningProcess (TestProcessDefinitionBy . clazz ( EchoTestProcess . class ) );
43+ .retrieveRunningProcess (ECHO_TEST_PROCESS );
3944
4045 if (runningProcess .isPresent ()) {
4146 try {
@@ -56,6 +61,14 @@ public static void sendToEchoProcess(TestProcessesRegistry registry, String line
5661 } catch (IOException e ) {
5762 throw new UncheckedIOException (e .getMessage (), e );
5863 }
64+
65+ // Wait for the line to appear on the echo process' stdOut
66+ try {
67+ registry .waitForEventOn (ECHO_TEST_PROCESS , LogPatternEventDetector .onStdOut ().withMarker (line ));
68+ } catch (TimeoutException e ) {
69+ throw new RuntimeException ("Timeout while waiting for the line to appear on the EchoProcess' stdOut" ,
70+ e );
71+ }
5972 } else {
6073 throw new IllegalStateException ("Trying to write to " + EchoTestProcess .class .getName ()
6174 + "'s stdIn, but no process is running." );
0 commit comments