-
Notifications
You must be signed in to change notification settings - Fork 0
Make every rule able to fail, and prove it #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
052069a
add a red/green fixture test for every shipped rule
SirCotare 0aef3db
match test class names and code unit bodies in one shared place
SirCotare 630fab9
report what a rule cannot verify instead of passing
SirCotare d52ba67
document the current API and the opt-out annotations
SirCotare e9af6da
allow rules a project has no code for, and guard the import instead
SirCotare 383cf46
use markdown javadoc
SirCotare 3ad7191
make the opt-outs usable once, and close the blacklist hole
SirCotare 059cb4f
use a multiline string for the empty-import message
SirCotare 74ed237
address review: lookup cost, null mappings, and an upgrade note
SirCotare File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
2 changes: 2 additions & 0 deletions
2
src/main/java/it/aboutbits/archunit/toolbox/CommonArchRuleCollection.java
This file contains hidden or 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,11 +1,13 @@ | ||
| package it.aboutbits.archunit.toolbox; | ||
|
|
||
| import it.aboutbits.archunit.toolbox.rule.base.AnalyzedPackagesMustContainClassesArchRule; | ||
| import it.aboutbits.archunit.toolbox.rule.common.ControllerRequestMappingsMustBeSecurityTested; | ||
| import it.aboutbits.archunit.toolbox.rule.common.SortMappingsExhaustiveArchRule; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| @NullMarked | ||
| public interface CommonArchRuleCollection extends | ||
| AnalyzedPackagesMustContainClassesArchRule, | ||
| ControllerRequestMappingsMustBeSecurityTested, | ||
| SortMappingsExhaustiveArchRule { | ||
| } |
This file contains hidden or 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
26 changes: 26 additions & 0 deletions
26
...a/it/aboutbits/archunit/toolbox/rule/base/AnalyzedPackagesMustContainClassesArchRule.java
This file contains hidden or 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,26 @@ | ||
| package it.aboutbits.archunit.toolbox.rule.base; | ||
|
|
||
| import com.tngtech.archunit.core.domain.JavaClasses; | ||
| import com.tngtech.archunit.junit.ArchTest; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| /// Checks that the analyzed packages contain any classes at all. | ||
| /// | ||
| /// Every other rule tolerates an empty selection, because whether a project has records, controllers | ||
| /// or `@Nested` test classes is the project's business and not something this library gets to require. | ||
| /// That leaves exactly one dangerous case: a mistyped or moved package in `@AnalyzeClasses` imports | ||
| /// nothing, and every rule then passes without looking at a single class. This rule is what turns that | ||
| /// into a failure, once, with a message that names the actual problem. | ||
| @SuppressWarnings({"checkstyle:InterfaceIsType", "java:S1214"}) | ||
| @NullMarked | ||
| public interface AnalyzedPackagesMustContainClassesArchRule { | ||
| @SuppressWarnings({"unused", "checkstyle:MethodName", "java:S100"}) | ||
| @ArchTest | ||
| default void analyzed_packages_must_contain_classes(JavaClasses classes) { | ||
| if (classes.isEmpty()) { | ||
| throw new AssertionError(""" | ||
| No classes were imported, so none of the architecture rules checked anything. | ||
| Verify the packages passed to @AnalyzeClasses."""); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ public boolean test(JavaClass javaClass) { | |
| } | ||
| } | ||
| ) | ||
| .allowEmptyShould(true) | ||
| .check(classes); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.