这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.baeldung.java9.process;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;

class ProcessWaitTest {

@Test
void givenAProcess_whenUsingWaitFor_thenNoExceptionThrown() {
// Code that interacts with a process should not throw IllegalMonitorStateException.
assertDoesNotThrow(() -> {
Process process = new ProcessBuilder("notepad.exe").start();
int exitCode = process.waitFor();
});
}

@Test
void givenAProcess_whenUsingWaitWithoutSynchronization_thenExceptionThrown() {
assertThrows(IllegalMonitorStateException.class, () -> {
Process process = new ProcessBuilder("notepad.exe").start();
process.wait();
});
}
}