From e64944578e226efa0580924acda0b2373e3a11da Mon Sep 17 00:00:00 2001 From: Lars Eckart Date: Mon, 6 Nov 2023 19:25:40 +0200 Subject: [PATCH] - B fixed issue with opening multiple files of Linux fixes #429 --- .../java/com/spun/util/tests/LinuxOpener.java | 2 +- .../com/spun/util/tests/LinuxOpenerTest.java | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 approvaltests-util/src/test/java/com/spun/util/tests/LinuxOpenerTest.java 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 ea37289ca..4a78840c0 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 000000000..d5505ab4f --- /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); + } +}