diff --git a/approvaltests-util/src/main/java/com/spun/util/tests/LinuxOpener.java b/approvaltests-util/src/main/java/com/spun/util/tests/LinuxOpener.java index ea37289c..4a78840c 100644 --- a/approvaltests-util/src/main/java/com/spun/util/tests/LinuxOpener.java +++ b/approvaltests-util/src/main/java/com/spun/util/tests/LinuxOpener.java @@ -23,8 +23,8 @@ public static String which(String command) { String command1 = "which " + command; Process p = Runtime.getRuntime().exec(command1); - String output = FileUtils.readStream(p.getInputStream()).trim(); p.waitFor(); + String output = FileUtils.readStream(p.getInputStream()).trim(); int exitValue = p.exitValue(); return exitValue == 0 ? output : null; } diff --git a/approvaltests-util/src/test/java/com/spun/util/tests/LinuxOpenerTest.java b/approvaltests-util/src/test/java/com/spun/util/tests/LinuxOpenerTest.java new file mode 100644 index 00000000..d5505ab4 --- /dev/null +++ b/approvaltests-util/src/test/java/com/spun/util/tests/LinuxOpenerTest.java @@ -0,0 +1,30 @@ +package com.spun.util.tests; + +import com.spun.util.io.FileUtils; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import java.io.File; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class LinuxOpenerTest +{ + @Disabled("This test takes a lot of time to run and opens a browser window") + @Test + void testMultipleFilesOnLinux() throws Exception + { + File tempFile = File.createTempFile("test", ".html"); + FileUtils.writeFile(tempFile, "

Applesauce

"); + int countCorrect = 0; + int totalRuns = 10; + for (int i = 0; i < totalRuns; i++) + { + if (LinuxOpener.executeOnLinux(tempFile.getAbsolutePath(), "open")) + { + countCorrect++; + } + } + assertEquals(totalRuns, countCorrect); + } +}