|
14 | 14 | import org.approvaltests.reporters.windows.WinMergeReporter; |
15 | 15 | import org.approvaltests.reporters.windows.WindowsDiffReporter; |
16 | 16 | import org.lambda.functions.Function1; |
| 17 | +import org.lambda.query.Queryable; |
17 | 18 |
|
18 | | -import java.util.Arrays; |
19 | 19 | import java.util.HashMap; |
20 | | -import java.util.List; |
21 | 20 | import java.util.Map; |
22 | 21 | import java.util.Objects; |
23 | | -import java.util.stream.Collectors; |
24 | 22 |
|
25 | 23 | public class EnvironmentVariableReporter implements ApprovalFailureReporter |
26 | 24 | { |
27 | | - private final ApprovalFailureReporter reporter; |
28 | 25 | // @formatter:off |
29 | 26 | private static final Map<String, Class<? extends ApprovalFailureReporter>> REPORTER_MAP = |
30 | 27 | new MapBuilder("AraxisMergeReporter", AraxisMergeReporter.class) |
@@ -58,33 +55,16 @@ public class EnvironmentVariableReporter implements ApprovalFailureReporter |
58 | 55 | public static final String ENVIRONMENT_VARIABLE_NAME = "APPROVAL_TESTS_USE_REPORTER"; |
59 | 56 | public static Function1<String, String> ENVIRONMENT_VARIABLES = System::getenv; |
60 | 57 | public static final EnvironmentVariableReporter INSTANCE = new EnvironmentVariableReporter(); |
| 58 | + private ApprovalFailureReporter reporter = null; |
61 | 59 | public EnvironmentVariableReporter() |
62 | 60 | { |
63 | 61 | String environmentValue = ENVIRONMENT_VARIABLES.call(ENVIRONMENT_VARIABLE_NAME); |
64 | 62 | 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); |
88 | 68 | } |
89 | 69 | public ApprovalFailureReporter getReporter() |
90 | 70 | { |
|
0 commit comments