Skip to content

Commit

Permalink
- F *breaking change* Introduce InlineOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsEckart committed May 6, 2024
1 parent 50e03d8 commit 9d34713
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ void testyMctest() {
@UseReporter(QuietReporter.class)
public void testReportingCode()
{
Options inlineWithCode = new Options().inline("", true);
Options inlineNoCode = new Options().inline("", false);
Options inlineWithCode = new Options().inline("", InlineOptions.showCode(true));
Options inlineNoCode = new Options().inline("", InlineOptions.showCode(false));
var resultWithCode = inlineWithCode.getReporter();
assertEquals(InlineJavaReporter.class, resultWithCode.getClass());
assertEquals(QuietReporter.class,
Expand All @@ -116,7 +116,7 @@ void testEmptyLineAtTheEnd()
var expected = """
Jeff Jeffty Jeff
born on Jeffteen of Jeff, Nineteen-eighty-Jeff
""";
Approvals.verify(greet("Jeff"), new Options().inline(expected));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.approvaltests.ReporterFactory;
import org.approvaltests.approvers.FileApprover;
import org.approvaltests.inline.InlineComparator;
import org.approvaltests.inline.InlineOptions;
import org.approvaltests.namer.ApprovalNamer;
import org.approvaltests.namer.NamerWrapper;
import org.approvaltests.scrubbers.NoOpScrubber;
Expand Down Expand Up @@ -32,11 +33,11 @@ public Options and(Function1<Options, Options> optionsUpdate)
}
public Options inline(String expected)
{
return inline(expected, true);
return inline(expected, InlineOptions.showCode(true));
}
public Options inline(String expected, boolean showCode)
public Options inline(String expected, InlineOptions inlineOptions)
{
InlineComparator inline = new InlineComparator(expected, showCode ? this.getReporter() : null);
InlineComparator inline = new InlineComparator(expected, inlineOptions);
return inline.setForOptions(this);
}
public Options(Scrubber scrubber)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.approvaltests.inline;

import com.spun.util.io.FileUtils;
import org.approvaltests.core.ApprovalFailureReporter;
import org.approvaltests.core.Options;
import org.approvaltests.namer.ApprovalNamer;

Expand All @@ -13,17 +12,14 @@

public class InlineComparator implements ApprovalNamer
{
private ApprovalFailureReporter reporter = null;
private final String expected;
private File approvedFile;
private File receivedFile;
public InlineComparator(String expected, ApprovalFailureReporter reporter)
private final InlineOptions inlineOptions;
private final String expected;
private File approvedFile;
private File receivedFile;
public InlineComparator(String expected, InlineOptions inlineOptions)
{
this.expected = expected;
if (reporter != null)
{
this.reporter = new InlineJavaReporter(reporter);
}
this.inlineOptions = inlineOptions;
}
@Override
public File getApprovedFile(String extensionWithDot)
Expand Down Expand Up @@ -73,16 +69,9 @@ public String getSourceFilePath()
{
return "";
}
public boolean report(String received, String approved)
{
return reporter.report(received, approved);
}
public Options setForOptions(Options options)
{
if (reporter != null)
{
options = options.withReporter(reporter);
}
options = inlineOptions.apply(options);
return options.forFile().withNamer(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.approvaltests.inline;

import org.approvaltests.core.Options;

public interface InlineOptions
{
Options apply(Options options);
public static InlineOptions showCode(boolean doShowCode)
{
if (doShowCode)
{
return new ShowCodeInlineOptions();
}
else
{
return new DoNotShowCodeInlineOptions();
}
}
public static class ShowCodeInlineOptions implements InlineOptions
{
public Options apply(Options options)
{
return options.withReporter(new InlineJavaReporter(options.getReporter()));
}
}
public static class DoNotShowCodeInlineOptions implements InlineOptions
{
public Options apply(Options options)
{
return options;
}
}
}

0 comments on commit 9d34713

Please sign in to comment.