-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #520 from FWest98/fw/environmentreporter
Implement support for environment variable-based reporters
- Loading branch information
Showing
10 changed files
with
198 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...ests-tests/src/test/java/org/approvaltests/reporters/EnvironmentVariableReporterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.approvaltests.reporters; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class EnvironmentVariableReporterTest { | ||
@Test | ||
public void testEnvironmentVariable() { | ||
var reporter = EnvironmentVariableReporter.INSTANCE.getReporter(); | ||
|
||
Assertions.assertInstanceOf(MultiReporter.class, reporter); | ||
var multiReporter = (MultiReporter) reporter; | ||
var reporters = multiReporter.getReporters(); | ||
|
||
Assertions.assertEquals(2, reporters.length); | ||
Assertions.assertInstanceOf(DiffReporter.class, reporters[0]); | ||
Assertions.assertInstanceOf(QuietReporter.class, reporters[1]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
approvaltests/src/main/java/org/approvaltests/reporters/BeyondCompareReporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.approvaltests.reporters; | ||
|
||
import org.approvaltests.reporters.macosx.BeyondCompareMacReporter; | ||
|
||
public class BeyondCompareReporter extends FirstWorkingReporter | ||
{ | ||
public static final BeyondCompareReporter INSTANCE = new BeyondCompareReporter(); | ||
public BeyondCompareReporter() | ||
{ | ||
super( | ||
org.approvaltests.reporters.windows.BeyondCompareReporter.INSTANCE, | ||
BeyondCompareMacReporter.INSTANCE | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
approvaltests/src/main/java/org/approvaltests/reporters/EnvironmentVariableReporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package org.approvaltests.reporters; | ||
|
||
import com.spun.util.ClassUtils; | ||
import org.approvaltests.core.ApprovalFailureReporter; | ||
import org.approvaltests.reporters.intellij.IntelliJReporter; | ||
import org.approvaltests.reporters.linux.MeldMergeReporter; | ||
import org.approvaltests.reporters.macosx.KaleidoscopeDiffReporter; | ||
import org.approvaltests.reporters.macosx.P4MergeReporter; | ||
import org.approvaltests.reporters.macosx.TkDiffReporter; | ||
import org.approvaltests.reporters.windows.*; | ||
|
||
import java.util.*; | ||
|
||
public class EnvironmentVariableReporter implements ApprovalFailureReporter { | ||
private final ApprovalFailureReporter reporter; | ||
|
||
private static final Map<String, Class<? extends ApprovalFailureReporter>> REPORTER_MAP = Map.ofEntries( | ||
Map.entry("AraxisMergeReporter", AraxisMergeReporter.class), | ||
Map.entry("AutoApproveReporter", AutoApproveReporter.class), | ||
Map.entry("AutoApproveWhenEmptyReporter", AutoApproveWhenEmptyReporter.class), | ||
Map.entry("BeyondCompareReporter", BeyondCompareReporter.class), | ||
Map.entry("ClipboardReporter", ClipboardReporter.class), | ||
Map.entry("CodeCompareReporter", CodeCompareReporter.class), | ||
Map.entry("DelayedClipboardReporter", DelayedClipboardReporter.class), | ||
Map.entry("DiffMergeReporter", DiffMergeReporter.class), | ||
Map.entry("DiffReporter", DiffReporter.class), | ||
Map.entry("FileCaptureReporter", FileCaptureReporter.class), | ||
Map.entry("ImageReporter", ImageReporter.class), | ||
Map.entry("ImageWebReporter", ImageWebReporter.class), | ||
Map.entry("IntelliJReporter", IntelliJReporter.class), | ||
Map.entry("JunitReporter", JunitReporter.class), | ||
Map.entry("KDiff3Reporter", KDiff3Reporter.class), | ||
Map.entry("KaleidoscopeDiffReporter", KaleidoscopeDiffReporter.class), | ||
Map.entry("MeldMergeReporter", MeldMergeReporter.class), | ||
Map.entry("P4MergeReporter", P4MergeReporter.class), | ||
Map.entry("PitReporter", PitReporter.class), | ||
Map.entry("QuietReporter", QuietReporter.class), | ||
Map.entry("TestNgReporter", TestNgReporter.class), | ||
Map.entry("TextWebReporter", TextWebReporter.class), | ||
Map.entry("TkDiffReporter", TkDiffReporter.class), | ||
Map.entry("TortoiseDiffReporter", TortoiseDiffReporter.class), | ||
Map.entry("VisualStudioCodeReporter", VisualStudioCodeReporter.class), | ||
Map.entry("WinMergeReporter", WinMergeReporter.class), | ||
Map.entry("WindowsDiffReporter", WindowsDiffReporter.class) | ||
); | ||
|
||
public static final String ENVIRONMENT_VARIABLE_NAME = "APPROVAL_TESTS_USE_REPORTER"; | ||
public static final EnvironmentVariableReporter INSTANCE = new EnvironmentVariableReporter(); | ||
|
||
public EnvironmentVariableReporter() { | ||
String environmentValue = System.getenv(ENVIRONMENT_VARIABLE_NAME); | ||
if(environmentValue == null) { | ||
reporter = null; | ||
return; | ||
} | ||
|
||
var reporters = Arrays.stream(environmentValue.split(",")) | ||
.distinct() | ||
.map(REPORTER_MAP::get) | ||
.filter(Objects::nonNull) | ||
.map(reporterType -> (ApprovalFailureReporter) ClassUtils.create(reporterType)) | ||
.toList(); | ||
|
||
switch(reporters.size()) { | ||
case 0: { | ||
reporter = null; | ||
break; | ||
} | ||
case 1: { | ||
reporter = reporters.get(0); | ||
break; | ||
} | ||
default: { | ||
reporter = new MultiReporter(reporters); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
public ApprovalFailureReporter getReporter() { | ||
return reporter; | ||
} | ||
|
||
@Override | ||
public boolean report(String received, String approved) { | ||
if(reporter == null) { | ||
return false; | ||
} | ||
|
||
return reporter.report(received, approved); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
approvaltests/src/main/java/org/approvaltests/reporters/VisualStudioCodeReporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.approvaltests.reporters; | ||
|
||
public class VisualStudioCodeReporter extends FirstWorkingReporter | ||
{ | ||
public static final VisualStudioCodeReporter INSTANCE = new VisualStudioCodeReporter(); | ||
public VisualStudioCodeReporter() | ||
{ | ||
super( | ||
org.approvaltests.reporters.windows.VisualStudioCodeReporter.INSTANCE, | ||
org.approvaltests.reporters.macosx.VisualStudioCodeReporter.INSTANCE | ||
); | ||
} | ||
} |