From 45bf77bf3df5b4d4eb9cd63d30a763a31e51cdfd Mon Sep 17 00:00:00 2001 From: Lars Eckart Date: Mon, 16 Sep 2024 20:02:24 +0300 Subject: [PATCH] ! r refactor to Queryable streams must have started using a method only available in 9, we compile with jdk 17 --- .../EnvironmentVariableReporter.java | 34 ++++--------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/approvaltests/src/main/java/org/approvaltests/reporters/EnvironmentVariableReporter.java b/approvaltests/src/main/java/org/approvaltests/reporters/EnvironmentVariableReporter.java index eb240295..dcdafa16 100644 --- a/approvaltests/src/main/java/org/approvaltests/reporters/EnvironmentVariableReporter.java +++ b/approvaltests/src/main/java/org/approvaltests/reporters/EnvironmentVariableReporter.java @@ -14,17 +14,14 @@ import org.approvaltests.reporters.windows.WinMergeReporter; import org.approvaltests.reporters.windows.WindowsDiffReporter; import org.lambda.functions.Function1; +import org.lambda.query.Queryable; -import java.util.Arrays; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.stream.Collectors; public class EnvironmentVariableReporter implements ApprovalFailureReporter { - private final ApprovalFailureReporter reporter; // @formatter:off private static final Map> REPORTER_MAP = new MapBuilder("AraxisMergeReporter", AraxisMergeReporter.class) @@ -58,33 +55,16 @@ public class EnvironmentVariableReporter implements ApprovalFailureReporter public static final String ENVIRONMENT_VARIABLE_NAME = "APPROVAL_TESTS_USE_REPORTER"; public static Function1 ENVIRONMENT_VARIABLES = System::getenv; public static final EnvironmentVariableReporter INSTANCE = new EnvironmentVariableReporter(); + private ApprovalFailureReporter reporter = null; public EnvironmentVariableReporter() { String environmentValue = ENVIRONMENT_VARIABLES.call(ENVIRONMENT_VARIABLE_NAME); if (environmentValue == null) - { - reporter = null; - return; - } - List reporters = Arrays.stream(environmentValue.split(",")).distinct() - .map(REPORTER_MAP::get).filter(Objects::nonNull) - .map(reporterType -> (ApprovalFailureReporter) ClassUtils.create(reporterType)) - .collect(Collectors.toList()); - switch (reporters.size()) - { - case 0 : { - reporter = null; - break; - } - case 1 : { - reporter = reporters.get(0); - break; - } - default : { - reporter = new MultiReporter(reporters); - break; - } - } + { return; } + Queryable split = Queryable.of(environmentValue.split(",")); + Queryable reporters = split.distinct().select(REPORTER_MAP::get) + .where(Objects::nonNull).select(reporterType -> (ApprovalFailureReporter) ClassUtils.create(reporterType)); + reporter = reporters.size() == 1 ? reporters.first() : new MultiReporter(reporters); } public ApprovalFailureReporter getReporter() {