diff --git a/core-java/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java b/core-java-9/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java similarity index 90% rename from core-java/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java rename to core-java-9/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java index a18cc3e368..0458383e99 100644 --- a/core-java/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java +++ b/core-java-9/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java @@ -1,6 +1,5 @@ package com.baeldung.processbuilder; -import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.hasItem; @@ -83,24 +82,6 @@ public class ProcessBuilderUnitTest { assertEquals("No errors should be detected", 0, exitCode); } - private List getDirectoryListingCommand() { - return isWindows() ? Arrays.asList("cmd.exe", "/c", "dir") : Arrays.asList("/bin/sh", "-c", "ls"); - } - - private List getGreetingCommand() { - return isWindows() ? Arrays.asList("cmd.exe", "/c", "echo %GREETING%") : Arrays.asList("/bin/bash", "-c", "echo $GREETING"); - } - - private List getEchoCommand() { - return isWindows() ? Arrays.asList("cmd.exe", "/c", "echo hello") : Arrays.asList("/bin/sh", "-c", "echo hello"); - } - - private boolean isWindows() { - return System.getProperty("os.name") - .toLowerCase() - .startsWith("windows"); - } - @Test public void givenProcessBuilder_whenRedirectStandardOutput_thenSuccessWriting() throws IOException, InterruptedException { ProcessBuilder processBuilder = new ProcessBuilder("java", "-version"); @@ -146,18 +127,20 @@ public class ProcessBuilderUnitTest { assertThat("Results should contain java version: ", lines, hasItem(containsString("java version"))); } -/* @Test + @Test public void givenProcessBuilder_whenStartingPipeline_thenSuccess() throws IOException, InterruptedException { - List builders = Arrays.asList( - new ProcessBuilder("find", "src", "-name", "*.java", "-type", "f"), - new ProcessBuilder("wc", "-l")); + if (!isWindows()) { + List builders = Arrays.asList( + new ProcessBuilder("find", "src", "-name", "*.java", "-type", "f"), + new ProcessBuilder("wc", "-l")); - List processes = ProcessBuilder.startPipeline(builders); - Process last = processes.get(processes.size() - 1); + List processes = ProcessBuilder.startPipeline(builders); + Process last = processes.get(processes.size() - 1); - List output = readOutput(last.getInputStream()); - assertThat("Results should not be empty", output, is(not(empty()))); - }*/ + List output = readOutput(last.getInputStream()); + assertThat("Results should not be empty", output, is(not(empty()))); + } + } @Test public void givenProcessBuilder_whenInheritIO_thenSuccess() throws IOException, InterruptedException { @@ -178,4 +161,22 @@ public class ProcessBuilderUnitTest { } } + private List getDirectoryListingCommand() { + return isWindows() ? Arrays.asList("cmd.exe", "/c", "dir") : Arrays.asList("/bin/sh", "-c", "ls"); + } + + private List getGreetingCommand() { + return isWindows() ? Arrays.asList("cmd.exe", "/c", "echo %GREETING%") : Arrays.asList("/bin/bash", "-c", "echo $GREETING"); + } + + private List getEchoCommand() { + return isWindows() ? Arrays.asList("cmd.exe", "/c", "echo hello") : Arrays.asList("/bin/sh", "-c", "echo hello"); + } + + private boolean isWindows() { + return System.getProperty("os.name") + .toLowerCase() + .startsWith("windows"); + } + }