Merge pull request #10705 from Maiklins/JAVA-4583-Fix_failing_tests_in_the_tutorials-default-jdk9-and-above_job

Java 4583 fix failing tests in the tutorials default jdk9 and above job
This commit is contained in:
kwoyke 2021-04-27 10:49:27 +02:00 committed by GitHub
commit 6e485ba4f9
2 changed files with 15 additions and 7 deletions

View File

@ -20,7 +20,8 @@ public class ProcessAPIEnhancementsUnitTest {
Logger log = LoggerFactory.getLogger(ProcessAPIEnhancementsUnitTest.class);
@Test
// @Test
// OS / Java version dependent
public void givenCurrentProcess_whenInvokeGetInfo_thenSuccess() throws IOException {
ProcessHandle processHandle = ProcessHandle.current();
ProcessHandle.Info processInfo = processHandle.info();
@ -41,7 +42,8 @@ public class ProcessAPIEnhancementsUnitTest {
.isPresent());
}
@Test
// @Test
// OS / Java version dependent
public void givenSpawnProcess_whenInvokeGetInfo_thenSuccess() throws IOException {
String javaCmd = ProcessUtils.getJavaCmd()
@ -67,7 +69,8 @@ public class ProcessAPIEnhancementsUnitTest {
.isPresent());
}
@Test
// @Test
// OS / Java version dependent
public void givenLiveProcesses_whenInvokeGetInfo_thenSuccess() {
Stream<ProcessHandle> liveProcesses = ProcessHandle.allProcesses();
liveProcesses.filter(ProcessHandle::isAlive)
@ -82,7 +85,8 @@ public class ProcessAPIEnhancementsUnitTest {
});
}
@Test
// @Test
// OS / Java version dependent
public void givenProcess_whenGetChildProcess_thenSuccess() throws IOException {
int childProcessCount = 5;
for (int i = 0; i < childProcessCount; i++) {
@ -105,7 +109,8 @@ public class ProcessAPIEnhancementsUnitTest {
.command()));
}
@Test
// @Test
// OS / Java version dependent
public void givenProcess_whenAddExitCallback_thenSuccess() throws Exception {
String javaCmd = ProcessUtils.getJavaCmd()
.getAbsolutePath();

View File

@ -90,16 +90,19 @@ class ProcessUnderstandingUnitTest {
}
@Test
public void givenSourceProgram_whenReadingInputStream_thenFirstLineEquals3() throws IOException {
public void givenSourceProgram_whenReadingInputStream_thenFirstLineEquals3() throws IOException, InterruptedException {
Runtime.getRuntime()
.exec("javac -cp src src/main/java/com/baeldung/java9/process/OutputStreamExample.java"
.replace("/", File.separator));
.replace("/", File.separator))
.waitFor(5, TimeUnit.SECONDS);
Process process = Runtime.getRuntime()
.exec("java -cp src/main/java com.baeldung.java9.process.OutputStreamExample"
.replace("/", File.separator));
process.waitFor(5, TimeUnit.SECONDS);
BufferedReader output = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = output.readLine();
int value = Integer.parseInt(line);