Skip to content

Commit

Permalink
- F improved error message
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsEckart committed Sep 23, 2024
1 parent 16fecf8 commit 86d64cf
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
org.approvaltests.ApprovalsDuplicateVerifyException: Already approved: file.txt
By default, ApprovalTests only allows one verify() call per test.
To find out more, visit:
https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/docs/reference/Naming.md
org.approvaltests.ApprovalsDuplicateVerifyException: By default, ApprovalTests only allows one verify() call per test.
This file has already been approved: file.txt

# Fixes
1. separate your test into two tests
2. add NamedParameters with the NamerFactory
3. Override Approvals.settings() with either
a. allowMultipleVerifyCallsForThisClass
b. allowMultipleVerifyCallsForThisMethod
You can do one of the following:

* Separate your test into two tests
* Allow multiple verify calls inside one test class or method via:
- Approvals.settings().allowMultipleVerifyCallsForThisClass();
- Approvals.settings().allowMultipleVerifyCallsForThisMethod();
* Add NamedParameters with the NamerFactory
- visit https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/docs/reference/Naming.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ void testSemiAutomaticMessage()
void testSemiAutomaticWithPreviousApproved()
{
var expected = """
42
***** DELETE ME TO APPROVE *****
vvvvv PREVIOUS RESULT vvvvv
41
""";
42
***** DELETE ME TO APPROVE *****
vvvvv PREVIOUS RESULT vvvvv
41
""";
var options = new Options().inline(expected, InlineOptions.semiAutomaticWithPreviousApproved());
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@

public class ApprovalsDuplicateVerifyException extends RuntimeException
{
// @formatter:off
public ApprovalsDuplicateVerifyException(String file)
{
super("Already approved: " + file + "\n"
+ "By default, ApprovalTests only allows one verify() call per test.\n" + "To find out more, visit: \n"
+ "https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/docs/reference/Naming.md\n\n"
+ "# Fixes\n" + "1. separate your test into two tests\n" + "2. add NamedParameters with the NamerFactory\n"
+ "3. Override Approvals.settings() with either \n" + "\ta. allowMultipleVerifyCallsForThisClass\n"
+ "\tb. allowMultipleVerifyCallsForThisMethod");
super(
"By default, ApprovalTests only allows one verify() call per test.\n"
+ "This file has already been approved: " + file + "\n"
+ "\n"
+ "You can do one of the following:\n"
+ "\n"
+ "* Separate your test into two tests\n"
+ "* Allow multiple verify calls inside one test class or method via:\n"
+ "\t- Approvals.settings().allowMultipleVerifyCallsForThisClass();\n"
+ "\t- Approvals.settings().allowMultipleVerifyCallsForThisMethod();\n"
+ "* Add NamedParameters with the NamerFactory\n"
+ "\t- visit https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/docs/reference/Naming.md\n"
);
}
// @formatter:on
}

0 comments on commit 86d64cf

Please sign in to comment.