Skip to content

Commit 45bf77b

Browse files
committed
! r refactor to Queryable
streams must have started using a method only available in 9, we compile with jdk 17
1 parent 1d44191 commit 45bf77b

File tree

1 file changed

+7
-27
lines changed

1 file changed

+7
-27
lines changed

approvaltests/src/main/java/org/approvaltests/reporters/EnvironmentVariableReporter.java

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@
1414
import org.approvaltests.reporters.windows.WinMergeReporter;
1515
import org.approvaltests.reporters.windows.WindowsDiffReporter;
1616
import org.lambda.functions.Function1;
17+
import org.lambda.query.Queryable;
1718

18-
import java.util.Arrays;
1919
import java.util.HashMap;
20-
import java.util.List;
2120
import java.util.Map;
2221
import java.util.Objects;
23-
import java.util.stream.Collectors;
2422

2523
public class EnvironmentVariableReporter implements ApprovalFailureReporter
2624
{
27-
private final ApprovalFailureReporter reporter;
2825
// @formatter:off
2926
private static final Map<String, Class<? extends ApprovalFailureReporter>> REPORTER_MAP =
3027
new MapBuilder("AraxisMergeReporter", AraxisMergeReporter.class)
@@ -58,33 +55,16 @@ public class EnvironmentVariableReporter implements ApprovalFailureReporter
5855
public static final String ENVIRONMENT_VARIABLE_NAME = "APPROVAL_TESTS_USE_REPORTER";
5956
public static Function1<String, String> ENVIRONMENT_VARIABLES = System::getenv;
6057
public static final EnvironmentVariableReporter INSTANCE = new EnvironmentVariableReporter();
58+
private ApprovalFailureReporter reporter = null;
6159
public EnvironmentVariableReporter()
6260
{
6361
String environmentValue = ENVIRONMENT_VARIABLES.call(ENVIRONMENT_VARIABLE_NAME);
6462
if (environmentValue == null)
65-
{
66-
reporter = null;
67-
return;
68-
}
69-
List<ApprovalFailureReporter> reporters = Arrays.stream(environmentValue.split(",")).distinct()
70-
.map(REPORTER_MAP::get).filter(Objects::nonNull)
71-
.map(reporterType -> (ApprovalFailureReporter) ClassUtils.create(reporterType))
72-
.collect(Collectors.toList());
73-
switch (reporters.size())
74-
{
75-
case 0 : {
76-
reporter = null;
77-
break;
78-
}
79-
case 1 : {
80-
reporter = reporters.get(0);
81-
break;
82-
}
83-
default : {
84-
reporter = new MultiReporter(reporters);
85-
break;
86-
}
87-
}
63+
{ return; }
64+
Queryable<String> split = Queryable.of(environmentValue.split(","));
65+
Queryable<ApprovalFailureReporter> reporters = split.distinct().select(REPORTER_MAP::get)
66+
.where(Objects::nonNull).select(reporterType -> (ApprovalFailureReporter) ClassUtils.create(reporterType));
67+
reporter = reporters.size() == 1 ? reporters.first() : new MultiReporter(reporters);
8868
}
8969
public ApprovalFailureReporter getReporter()
9070
{

0 commit comments

Comments
 (0)