-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*** added a way to allow multiple verify per test
- Loading branch information
1 parent
577f636
commit 8239acb
Showing
8 changed files
with
40 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
approvaltests/src/main/java/org/approvaltests/ApprovalSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.approvaltests; | ||
|
||
import com.spun.util.introspection.Caller; | ||
import org.approvaltests.approvers.FileApprover; | ||
import org.lambda.query.Queryable; | ||
|
||
public class ApprovalSettings | ||
{ | ||
public void allowMultipleVerifyCallsForThisMethod() | ||
{ | ||
StackTraceElement caller = Caller.get(1); | ||
String className = Queryable.as(caller.getClassName().split("\\.")).last(); | ||
String methodName = caller.getMethodName(); | ||
String name = className + "." + methodName; | ||
FileApprover.tracker.addAllowedDuplicates(f -> f.contains(name)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 9 additions & 2 deletions
11
approvaltests/src/main/java/org/approvaltests/approvers/ApprovalTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
package org.approvaltests.approvers; | ||
|
||
import org.approvaltests.ApprovalsDuplicateVerifyException; | ||
import org.lambda.functions.Function1; | ||
import org.lambda.query.Queryable; | ||
|
||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
|
||
public class ApprovalTracker | ||
{ | ||
private final Set<String> tracked = new LinkedHashSet<>(); | ||
private final Set<String> tracked = new LinkedHashSet<>(); | ||
private final Queryable<Function1<String, Boolean>> allowedDuplicates = new Queryable<>(); | ||
public void assertUnique(String approved) | ||
{ | ||
if (tracked.contains(approved)) | ||
if (tracked.contains(approved) && !allowedDuplicates.any(f -> f.call(approved))) | ||
{ throw new ApprovalsDuplicateVerifyException(approved); } | ||
tracked.add(approved); | ||
} | ||
public void addAllowedDuplicates(Function1<String, Boolean> duplicateChecker) | ||
{ | ||
allowedDuplicates.add(duplicateChecker); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters