Skip to content

Commit 12ad7c4

Browse files
committed
- F ReportNothing
1 parent 5bc4200 commit 12ad7c4

File tree

9 files changed

+45
-22
lines changed

9 files changed

+45
-22
lines changed

approvaltests-tests/src/test/java/org/approvaltests/ApprovalsTest.java

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

33
import org.approvaltests.core.Options;
4-
import org.approvaltests.reporters.ClipboardReporter;
5-
import org.approvaltests.reporters.DiffReporter;
6-
import org.approvaltests.reporters.QuietReporter;
7-
import org.approvaltests.reporters.UseReporter;
4+
import org.approvaltests.reporters.*;
85
import org.approvaltests.reporters.windows.BeyondCompareReporter;
96
import org.junit.jupiter.api.Test;
107

@@ -37,7 +34,7 @@ public void testWrongCall()
3734
Approvals.verifyException(() -> {
3835
JButton b = new JButton("Approval Tests Rule");
3936
b.setPreferredSize(new Dimension(150, 20));
40-
Approvals.verify(b, new Options(new QuietReporter()));
37+
Approvals.verify(b, new Options(new ReportNothing()));
4138
});
4239
}
4340
@Test

approvaltests-tests/src/test/java/org/approvaltests/OptionsSamplesTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.approvaltests.core.Options;
44
import org.approvaltests.reporters.QuietReporter;
5+
import org.approvaltests.reporters.ReportNothing;
56
import org.approvaltests.scrubbers.GuidScrubber;
67
import org.junit.jupiter.api.Test;
78

@@ -12,7 +13,7 @@ void showAll()
1213
{
1314
Options options =
1415
// begin-snippet: specify_all_the_options
15-
new Options().withReporter(new QuietReporter()).withScrubber(new GuidScrubber()).forFile()
16+
new Options().withReporter(new ReportNothing()).withScrubber(new GuidScrubber()).forFile()
1617
.withExtension(".json");
1718
// end-snippet
1819
}

approvaltests-tests/src/test/java/org/approvaltests/approvers/FileApproverTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.approvaltests.approvers;
22

33
import com.spun.util.ObjectUtils;
4+
import com.spun.util.QuietAutoCloseable;
45
import com.spun.util.io.FileUtils;
56
import com.spun.util.tests.StackTraceReflectionResult;
67
import com.spun.util.tests.TestUtils;
@@ -71,13 +72,12 @@ public void testCustomApprover()
7172
// end-snippet
7273
}
7374
@Test
74-
void testCustomError() throws Exception
75+
void testCustomError()
7576
{
7677
var expected = """
7778
java.lang.AssertionError: Custom message
7879
""";
79-
try (AutoCloseable old = Approvals.settings()
80-
.registerErrorGenerator((received, approved) -> new AssertionError("Custom message")))
80+
try (var old = ApprovalSettings.registerErrorGenerator((r, a) -> new AssertionError("Custom message")))
8181
{
8282
FileApprover fileApprover = new FileApprover(new File("a.txt"), new File("b.txt"), null, null);
8383
Approvals.verifyException(fileApprover::fail, new Options().inline(expected));

approvaltests-util-tests/src/test/java/com/spun/util/persistence/LoadersAndSaversExamplesTest.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.spun.util.Tuple;
44
import org.approvaltests.Approvals;
5+
import org.approvaltests.utils.ConsoleOutput;
56
import org.junit.jupiter.api.Nested;
67
import org.junit.jupiter.api.Test;
78

@@ -40,12 +41,15 @@ class Step0_5
4041
@Test
4142
void test_dump_data()
4243
{
43-
MyDatabase database = new MyDatabase();
44-
// begin-snippet: step_capture_data
45-
List<Customer> seniorCustomers = database.getSeniorCustomers();
46-
seniorCustomers.stream().forEach(System.out::println);
47-
// end-snippet
48-
Approvals.verifyAll("", seniorCustomers, c -> c.toString());
44+
try (var __ = new ConsoleOutput())
45+
{
46+
MyDatabase database = new MyDatabase();
47+
// begin-snippet: step_capture_data
48+
List<Customer> seniorCustomers = database.getSeniorCustomers();
49+
seniorCustomers.stream().forEach(System.out::println);
50+
// end-snippet
51+
Approvals.verifyAll("", seniorCustomers, c -> c.toString());
52+
}
4953
}
5054
public class MyDatabase
5155
{

approvaltests/src/main/java/org/approvaltests/ApprovalSettings.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.approvaltests;
22

3+
import com.spun.util.QuietAutoCloseable;
34
import com.spun.util.introspection.Caller;
45
import org.approvaltests.approvers.FileApprover;
56
import org.lambda.functions.Function2;
@@ -23,7 +24,7 @@ public void allowMultipleVerifyCallsForThisClass()
2324
String className = caller.getClassName().replace('.', File.separatorChar);
2425
FileApprover.tracker.addAllowedDuplicates(f -> f.contains(className));
2526
}
26-
public static AutoCloseable registerErrorGenerator(Function2<String, String, Error> errorGenerator)
27+
public static QuietAutoCloseable registerErrorGenerator(Function2<String, String, Error> errorGenerator)
2728
{
2829
return FileApprover.registerErrorGenerator(errorGenerator);
2930
}

approvaltests/src/main/java/org/approvaltests/approvers/FileApprover.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.approvaltests.approvers;
22

33
import com.spun.util.ObjectUtils;
4+
import com.spun.util.QuietAutoCloseable;
45
import com.spun.util.io.FileUtils;
56
import org.approvaltests.internal.logs.ApprovedFileLog;
67
import org.approvaltests.internal.logs.FailedFileLog;
@@ -39,7 +40,7 @@ public FileApprover(File received, File approved, ApprovalWriter writer,
3940
this.writer = writer;
4041
this.approver = approver;
4142
}
42-
public static AutoCloseable registerErrorGenerator(Function2<String, String, Error> errorGenerator)
43+
public static QuietAutoCloseable registerErrorGenerator(Function2<String, String, Error> errorGenerator)
4344
{
4445
Function2<String, String, Error> old = FileApprover.errorGenerator;
4546
FileApprover.errorGenerator = errorGenerator;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.spun.util.SystemUtils;
44
import com.spun.util.WindowUtils;
5+
import com.spun.util.logger.SimpleLogger;
56
import org.approvaltests.core.ApprovalFailureReporter;
67

78
import java.awt.*;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.approvaltests.reporters;
2+
3+
import org.approvaltests.core.ApprovalFailureReporter;
4+
5+
public class ReportNothing implements ApprovalFailureReporter
6+
{
7+
public static final ReportNothing INSTANCE = new ReportNothing();
8+
@Override
9+
public boolean report(String received, String approved)
10+
{
11+
return true;
12+
}
13+
}

approvaltests/src/test/java/org/approvaltests/reporters/JUnitReporterTest.java

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

33
import com.spun.util.ClassUtils;
4+
import com.spun.util.QuietAutoCloseable;
45
import com.spun.util.io.FileUtils;
6+
import com.spun.util.logger.SimpleLogger;
57
import org.approvaltests.Approvals;
68
import org.approvaltests.core.ApprovalFailureReporter;
79
import org.junit.jupiter.api.Test;
@@ -25,10 +27,13 @@ void testJUnit5()
2527
}
2628
private void verifyReporter(ApprovalFailureReporter reporter)
2729
{
28-
String a = FileUtils.getResolvedPath(ClassUtils.getAdjacentFile(this.getClass(), "a.txt"));
29-
String b = FileUtils.getResolvedPath(ClassUtils.getAdjacentFile(this.getClass(), "b.txt"));
30-
Approvals.verifyException(() -> {
31-
reporter.report(b, a);
32-
});
30+
try (QuietAutoCloseable l = SimpleLogger.quiet())
31+
{
32+
String a = FileUtils.getResolvedPath(ClassUtils.getAdjacentFile(this.getClass(), "a.txt"));
33+
String b = FileUtils.getResolvedPath(ClassUtils.getAdjacentFile(this.getClass(), "b.txt"));
34+
Approvals.verifyException(() -> {
35+
reporter.report(b, a);
36+
});
37+
}
3338
}
3439
}

0 commit comments

Comments
 (0)