8
8
import java .io .UncheckedIOException ;
9
9
import java .nio .charset .StandardCharsets ;
10
10
import java .util .Optional ;
11
+ import java .util .concurrent .TimeoutException ;
11
12
12
13
import org .junit .jupiter .api .Assertions ;
13
14
import org .opentest4j .AssertionFailedError ;
17
18
import io .github .netmikey .testprocesses .TestProcessDefinitionBy ;
18
19
import io .github .netmikey .testprocesses .TestProcessState ;
19
20
import io .github .netmikey .testprocesses .TestProcessesRegistry ;
21
+ import io .github .netmikey .testprocesses .eventdetector .LogPatternEventDetector ;
20
22
21
23
/**
22
24
* Utility method for asserting and interacting with those test processes
23
25
* specifically created for these framework-tests.
24
26
*/
25
27
public class TestHelper {
26
28
29
+ private static final TestProcessDefinitionBy <EchoTestProcess > ECHO_TEST_PROCESS = TestProcessDefinitionBy
30
+ .clazz (EchoTestProcess .class );
31
+
27
32
/**
28
33
* Sends a line of test to the {@link EchoTestProcess} currently running in
29
34
* the specified registry.
@@ -35,7 +40,7 @@ public class TestHelper {
35
40
*/
36
41
public static void sendToEchoProcess (TestProcessesRegistry registry , String line ) {
37
42
Optional <RunningTestProcess <EchoTestProcess >> runningProcess = registry
38
- .retrieveRunningProcess (TestProcessDefinitionBy . clazz ( EchoTestProcess . class ) );
43
+ .retrieveRunningProcess (ECHO_TEST_PROCESS );
39
44
40
45
if (runningProcess .isPresent ()) {
41
46
try {
@@ -56,6 +61,14 @@ public static void sendToEchoProcess(TestProcessesRegistry registry, String line
56
61
} catch (IOException e ) {
57
62
throw new UncheckedIOException (e .getMessage (), e );
58
63
}
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
+ }
59
72
} else {
60
73
throw new IllegalStateException ("Trying to write to " + EchoTestProcess .class .getName ()
61
74
+ "'s stdIn, but no process is running." );
0 commit comments