Skip to content

Commit 8c0ab21

Browse files
committed
- B FirstWorkingReporter does not swallow reporters with approval power
#446
1 parent 88a0295 commit 8c0ab21

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.approvaltests.reporters;
2+
3+
import org.approvaltests.Approvals;
4+
import org.approvaltests.core.Options;
5+
import org.approvaltests.core.VerifyResult;
6+
import org.junit.jupiter.api.Test;
7+
8+
class FirstWorkingReporterTest {
9+
10+
@Test
11+
void testReporterWithApprovalPower() {
12+
var t = new ReporterWithApprovalPower() {
13+
14+
@Override
15+
public boolean report(String received, String approved) {
16+
return true;
17+
}
18+
19+
@Override
20+
public VerifyResult approveWhenReported() {
21+
return VerifyResult.SUCCESS;
22+
}
23+
};
24+
Approvals.verify("test", new Options(new FirstWorkingReporter(t)));
25+
}
26+
}

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package org.approvaltests.reporters;
22

33
import org.approvaltests.core.ApprovalFailureReporter;
4+
import org.approvaltests.core.VerifyResult;
45

5-
public class FirstWorkingReporter implements ApprovalFailureReporter
6+
public class FirstWorkingReporter implements ReporterWithApprovalPower
67
{
78
private final ApprovalFailureReporter[] reporters;
9+
private VerifyResult approvalOutcome = VerifyResult.FAILURE;
10+
811
public FirstWorkingReporter(ApprovalFailureReporter... reporters)
912
{
1013
this.reporters = reporters;
@@ -19,10 +22,20 @@ public boolean report(String received, String approved)
1922
for (ApprovalFailureReporter reporter : reporters)
2023
{
2124
if (reporter.report(received, approved))
22-
{ return true; }
25+
{
26+
checkApprovalPower(reporter);
27+
return true;
28+
}
2329
}
2430
return false;
2531
}
32+
33+
private void checkApprovalPower(ApprovalFailureReporter reporter) {
34+
if (reporter instanceof ReporterWithApprovalPower) {
35+
approvalOutcome = ((ReporterWithApprovalPower) reporter).approveWhenReported();
36+
}
37+
}
38+
2639
public ApprovalFailureReporter[] getReporters()
2740
{
2841
return reporters;
@@ -32,4 +45,9 @@ public String toString()
3245
{
3346
return getClass().getName();
3447
}
48+
49+
@Override
50+
public VerifyResult approveWhenReported() {
51+
return approvalOutcome;
52+
}
3553
}

0 commit comments

Comments
 (0)