Skip to content

Commit

Permalink
- F Options.addReporter(reporter)
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsEckart committed May 13, 2024
1 parent b336f9f commit 7399174
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.approvaltests;

import com.spun.util.ArrayUtils;
import com.spun.util.introspection.Caller;
import org.approvaltests.approvers.FileApprover;
import org.approvaltests.awt.AwtApprovals;
import org.approvaltests.combinations.CombinationApprovals;
Expand All @@ -10,6 +9,9 @@
import org.approvaltests.core.Options;
import org.approvaltests.core.VerifyResult;
import org.approvaltests.reporters.FirstWorkingReporter;
import org.approvaltests.reporters.Junit4Reporter;
import org.approvaltests.reporters.Junit5Reporter;
import org.approvaltests.reporters.MultiReporter;
import org.approvaltests.reporters.UseReporter;
import org.approvaltests.reporters.UseReporterTest;
import org.approvaltests.velocity.VelocityApprovals;
Expand Down Expand Up @@ -195,4 +197,17 @@ void verifyCustomComparator()
{
Approvals.verify("The approval file is empty", new Options().withComparator((a, b) -> VerifyResult.SUCCESS));
}
@Test
void testAddReporter()
{
Options options = new Options().withReporter(new Junit5Reporter()).withReporter(new Junit4Reporter());
ApprovalFailureReporter reporter = options.getReporter();
assertTrue(reporter instanceof Junit4Reporter);
Options options2 = new Options().withReporter(new MultiReporter(new Junit5Reporter(), new Junit4Reporter()));
ApprovalFailureReporter reporter2 = options2.getReporter();
assertEquals(reporter2.toString(), "Junit5Reporter, Junit4Reporter");
Options options3 = new Options().withReporter(new Junit5Reporter()).andReporter(new Junit4Reporter());
ApprovalFailureReporter reporter3 = options3.getReporter();
assertEquals(reporter3.toString(), "Junit5Reporter, Junit4Reporter");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.approvaltests.inline.InlineOptions;
import org.approvaltests.namer.ApprovalNamer;
import org.approvaltests.namer.NamerWrapper;
import org.approvaltests.reporters.MultiReporter;
import org.approvaltests.scrubbers.NoOpScrubber;
import org.approvaltests.writers.ApprovalWriterFactory;
import org.approvaltests.writers.DefaultApprovalWriterFactory;
Expand Down Expand Up @@ -61,6 +62,10 @@ public Options withReporter(ApprovalFailureReporter reporter)
{
return new Options(fields, Fields.REPORTER, reporter);
}
public Options andReporter(ApprovalFailureReporter reporter)
{
return this.withReporter(new MultiReporter(this.getReporter(), reporter));
}
public Function2<File, File, VerifyResult> getComparator()
{
return ArrayUtils.getOrElse(fields, Fields.COMPARATOR, () -> FileApprover::approveTextFile);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.approvaltests.reporters;

import org.approvaltests.core.ApprovalFailureReporter;
import org.lambda.query.Queryable;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -40,4 +41,9 @@ public ApprovalFailureReporter[] getReporters()
{
return reporters.toArray(new ApprovalFailureReporter[0]);
}
@Override
public String toString()
{
return Queryable.as(reporters.stream()).join(", ", r -> r.getClass().getSimpleName());
}
}

0 comments on commit 7399174

Please sign in to comment.