File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
core-java-modules/core-java-os-2/src/test/java/com/baeldung/java9/process Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .baeldung .java9 .process ;
2
+
3
+ import org .junit .jupiter .api .Test ;
4
+ import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
5
+ import static org .junit .jupiter .api .Assertions .assertThrows ;
6
+
7
+ class ProcessWaitTest {
8
+
9
+ @ Test
10
+ void givenAProcess_whenUsingWaitFor_thenNoExceptionThrown () {
11
+ // Code that interacts with a process should not throw IllegalMonitorStateException.
12
+ assertDoesNotThrow (() -> {
13
+ Process process = new ProcessBuilder ("notepad.exe" ).start ();
14
+ int exitCode = process .waitFor ();
15
+ });
16
+ }
17
+
18
+ @ Test
19
+ void givenAProcess_whenUsingWaitWithoutSynchronization_thenExceptionThrown () {
20
+ assertThrows (IllegalMonitorStateException .class , () -> {
21
+ Process process = new ProcessBuilder ("notepad.exe" ).start ();
22
+ process .wait ();
23
+ });
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments