Skip to content

Commit

Permalink
- B FirstWorkingReporter does not swallow reporters with approval power
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottBob committed Feb 13, 2025
1 parent 88a0295 commit 8c0ab21
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.approvaltests.reporters;

import org.approvaltests.Approvals;
import org.approvaltests.core.Options;
import org.approvaltests.core.VerifyResult;
import org.junit.jupiter.api.Test;

class FirstWorkingReporterTest {

@Test
void testReporterWithApprovalPower() {
var t = new ReporterWithApprovalPower() {

@Override
public boolean report(String received, String approved) {
return true;
}

@Override
public VerifyResult approveWhenReported() {
return VerifyResult.SUCCESS;
}
};
Approvals.verify("test", new Options(new FirstWorkingReporter(t)));
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.approvaltests.reporters;

import org.approvaltests.core.ApprovalFailureReporter;
import org.approvaltests.core.VerifyResult;

public class FirstWorkingReporter implements ApprovalFailureReporter
public class FirstWorkingReporter implements ReporterWithApprovalPower
{
private final ApprovalFailureReporter[] reporters;
private VerifyResult approvalOutcome = VerifyResult.FAILURE;

public FirstWorkingReporter(ApprovalFailureReporter... reporters)
{
this.reporters = reporters;
Expand All @@ -19,10 +22,20 @@ public boolean report(String received, String approved)
for (ApprovalFailureReporter reporter : reporters)
{
if (reporter.report(received, approved))
{ return true; }
{
checkApprovalPower(reporter);
return true;
}
}
return false;
}

private void checkApprovalPower(ApprovalFailureReporter reporter) {
if (reporter instanceof ReporterWithApprovalPower) {
approvalOutcome = ((ReporterWithApprovalPower) reporter).approveWhenReported();
}
}

public ApprovalFailureReporter[] getReporters()
{
return reporters;
Expand All @@ -32,4 +45,9 @@ public String toString()
{
return getClass().getName();
}

@Override
public VerifyResult approveWhenReported() {
return approvalOutcome;
}
}

0 comments on commit 8c0ab21

Please sign in to comment.