diff --git a/approvaltests-tests/src/test/java/org/approvaltests/reporters/IntelliJResolverTest.java b/approvaltests-tests/src/test/java/org/approvaltests/reporters/IntelliJResolverTest.java index 2a994a7e..abb3ae6a 100644 --- a/approvaltests-tests/src/test/java/org/approvaltests/reporters/IntelliJResolverTest.java +++ b/approvaltests-tests/src/test/java/org/approvaltests/reporters/IntelliJResolverTest.java @@ -7,40 +7,45 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals; -class IntelliJResolverTest { - @Test - void testFindItOnMac() { - Queryable validPaths = Queryable.as("/Applications/IntelliJ IDEA.app/Contents/MacOS/idea", - "Users/lars/Applications/IntelliJ IDEA Ultimate.app/Contents/MacOS/idea", - "Users/lars/Applications/IntelliJ IDEA Community.app/Contents/MacOS/idea", - "Users/lars/Applications/IntelliJ IDEA Community Edition.app/Contents/MacOS/idea"); - verifyPaths(IntelliJToolboxResolver::getDiffInfoMac, "Users/lars", validPaths); +class IntelliJResolverTest +{ + @Test + void testFindItOnMac() + { + Queryable validPaths = Queryable.as("/Applications/IntelliJ IDEA.app/Contents/MacOS/idea", + "Users/lars/Applications/IntelliJ IDEA Ultimate.app/Contents/MacOS/idea", + "Users/lars/Applications/IntelliJ IDEA Community.app/Contents/MacOS/idea", + "Users/lars/Applications/IntelliJ IDEA Community Edition.app/Contents/MacOS/idea"); + verifyPaths(IntelliJToolboxResolver::getDiffInfoMac, "Users/lars", validPaths); + } + private static void verifyPaths(Function2, DiffInfo> finder, String userHome, + Queryable validPaths) + { + for (String path : validPaths) + { + DiffInfo diffInfo = finder.call(userHome, f -> f.equals(path)); + assertNotEquals("", diffInfo.diffProgram, path); } - - private static void verifyPaths(Function2, DiffInfo> finder, String userHome, Queryable validPaths) { - for (String path : validPaths) { - DiffInfo diffInfo = finder.call(userHome, f -> f.equals(path)); - assertNotEquals("", diffInfo.diffProgram, path); - } - } - - @Test - void testFindItOnLinux() { - Queryable validPaths = Queryable.as( - "/home/lars/.local/share/JetBrains/Toolbox/apps/intellij-idea-ultimate/bin/idea.sh", - "/home/lars/.local/share/JetBrains/Toolbox/apps/intellij-idea-community-edition/bin/idea.sh"); - verifyPaths(IntelliJToolboxResolver::getDiffInfoLinux, "/home/lars", validPaths); - } - - // "C:\Users\larse\AppData\Local\Programs\IntelliJ IDEA Ultimate\bin\idea64.exe" - @Test - void testFindItOnWindows() { - Queryable validPaths = Queryable.as( - "C:\\Users\\larse\\AppData\\Local\\Programs\\IntelliJ IDEA Ultimate\\bin\\idea64.exe"); - String[] programFiles = {"C:\\Users\\larse\\AppData\\Local\\Programs"}; - for (String path : validPaths) { - DiffInfo diffInfo = IntelliJToolboxResolver.getDiffInfoWindows(programFiles, f -> f.equals(path)); - assertNotEquals("", diffInfo.diffProgram, path); - } + } + @Test + void testFindItOnLinux() + { + Queryable validPaths = Queryable.as( + "/home/lars/.local/share/JetBrains/Toolbox/apps/intellij-idea-ultimate/bin/idea.sh", + "/home/lars/.local/share/JetBrains/Toolbox/apps/intellij-idea-community-edition/bin/idea.sh"); + verifyPaths(IntelliJToolboxResolver::getDiffInfoLinux, "/home/lars", validPaths); + } + // "C:\Users\larse\AppData\Local\Programs\IntelliJ IDEA Ultimate\bin\idea64.exe" + @Test + void testFindItOnWindows() + { + Queryable validPaths = Queryable + .as("C:\\Users\\larse\\AppData\\Local\\Programs\\IntelliJ IDEA Ultimate\\bin\\idea64.exe"); + String[] programFiles = {"C:\\Users\\larse\\AppData\\Local\\Programs"}; + for (String path : validPaths) + { + DiffInfo diffInfo = IntelliJToolboxResolver.getDiffInfoWindows(programFiles, f -> f.equals(path)); + assertNotEquals("", diffInfo.diffProgram, path); } + } } diff --git a/approvaltests/src/main/java/org/approvaltests/reporters/DiffInfo.java b/approvaltests/src/main/java/org/approvaltests/reporters/DiffInfo.java index 0c74833d..b02a9f81 100644 --- a/approvaltests/src/main/java/org/approvaltests/reporters/DiffInfo.java +++ b/approvaltests/src/main/java/org/approvaltests/reporters/DiffInfo.java @@ -3,6 +3,7 @@ import com.spun.util.ArrayUtils; import java.io.File; +import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Objects; @@ -60,12 +61,25 @@ public boolean isEmpty() } public static String[] getProgramFilesPaths() { - HashSet paths = new HashSet<>(); - paths.add(System.getenv("ProgramFiles(x86)")); - paths.add(System.getenv("ProgramFiles")); - paths.add(System.getenv("ProgramW6432")); - paths.add(System.getenv("LOCALAPPDATA") + "\\Programs"); - return paths.stream().filter(Objects::nonNull).toArray(String[]::new); + List paths = new ArrayList<>(); + addIfNotNull("ProgramFiles(x86)", paths); + addIfNotNull("ProgramFiles(x86)", paths); + addIfNotNull("ProgramFiles", paths); + addIfNotNull("ProgramW6432", paths); + addIfNotNull("LOCALAPPDATA", paths, "\\Programs"); + return paths.toArray(new String[0]); + } + private static void addIfNotNull(String envVarName, List paths) + { + addIfNotNull(envVarName, paths, ""); + } + private static void addIfNotNull(String envVarName, List paths, String postfix) + { + String path = System.getenv(envVarName); + if (path != null) + { + paths.add(path + postfix); + } } public static class One { diff --git a/approvaltests/src/main/java/org/approvaltests/reporters/IntelliJToolboxResolver.java b/approvaltests/src/main/java/org/approvaltests/reporters/IntelliJToolboxResolver.java index 869d3f45..fbd31a57 100644 --- a/approvaltests/src/main/java/org/approvaltests/reporters/IntelliJToolboxResolver.java +++ b/approvaltests/src/main/java/org/approvaltests/reporters/IntelliJToolboxResolver.java @@ -12,7 +12,6 @@ public class IntelliJToolboxResolver { private interface Resolver extends Function2, DiffInfo> { - } public static DiffInfo findIt() { @@ -43,15 +42,16 @@ public static DiffInfo getDiffInfoLinux(String userHome, Function1 fileExists) { + public static DiffInfo getDiffInfoWindows(String[] programFiles, Function1 fileExists) + { Queryable applications = as("IntelliJ IDEA Ultimate", "IntelliJ IDEA", "IntelliJ IDEA Community", - "IntelliJ IDEA Community Edition"); + "IntelliJ IDEA Community Edition"); Queryable locations = Queryable.as(programFiles); String postfix = "\\bin\\idea64.exe"; return getDiffInfo(fileExists, locations, applications, postfix, "\\"); } private static DiffInfo getDiffInfo(Function1 fileExists, Queryable locations, - Queryable applications, String postfix, String pathSeparator) + Queryable applications, String postfix, String pathSeparator) { Queryable paths = locations.selectMany(l -> applications.select(a -> l + pathSeparator + a + postfix)); String matching = paths.first(fileExists);