Skip to content

Commit 895514d

Browse files
authored
BAEL-9318 Resolving Current Thread Not Owner Exception (#18601)
* Create ProcessWaitTest.java * Update ProcessWaitTest.java
1 parent 5577066 commit 895514d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}

0 commit comments

Comments
 (0)