From ce041e376313fc4b5313ccd65f441ad3bd64b43f Mon Sep 17 00:00:00 2001 From: Lars Eckart Date: Mon, 23 Oct 2023 19:32:24 +0300 Subject: [PATCH] . t remove duplication Co-Authored-By: Llewellyn Falco --- .../reporters/IntelliJResolverTest.java | 51 +++++++++---------- 1 file changed, 24 insertions(+), 27 deletions(-) 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 e5c521c9..d7290c20 100644 --- a/approvaltests-tests/src/test/java/org/approvaltests/reporters/IntelliJResolverTest.java +++ b/approvaltests-tests/src/test/java/org/approvaltests/reporters/IntelliJResolverTest.java @@ -1,37 +1,34 @@ package org.approvaltests.reporters; import org.junit.jupiter.api.Test; +import org.lambda.functions.Function1; +import org.lambda.functions.Function2; import org.lambda.query.Queryable; import static org.junit.jupiter.api.Assertions.assertNotEquals; -class IntelliJResolverTest -{ - @Test - void testFindItOnMac() - { - String userHome = "Users/lars"; - 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"); - for (String path : validPaths) - { - DiffInfo diffInfo = IntelliJToolboxResolver.getDiffInfoMac(userHome, f -> f.equals(path)); - assertNotEquals("", diffInfo.diffProgram, path); +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); } - } - @Test - void testFindItOnLinux() - { - String userHome = "/home/lars"; - 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"); - for (String path : validPaths) - { - DiffInfo diffInfo = IntelliJToolboxResolver.getDiffInfoLinux(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); } - } }