-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple demo, how accesses by classes that are annotated with @Allow c…
…an be ignored. Remove @Allow from Okay.java and the violation will be reported (likewise, add it to Bad.java and the test will pass). Note that annotations may not be @retention(SOURCE) to be picked up.
- Loading branch information
1 parent
3fd3247
commit 7a7e3d5
Showing
5 changed files
with
46 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.bar; | ||
|
||
public @interface Allow { | ||
} |
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,4 @@ | ||
package com.bar.evil; | ||
|
||
public class Evil { | ||
} |
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,9 @@ | ||
package com.bar.some; | ||
|
||
import com.bar.evil.Evil; | ||
|
||
public class Bad { | ||
public Bad() { | ||
new Evil(); | ||
} | ||
} |
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,11 @@ | ||
package com.bar.some; | ||
|
||
import com.bar.Allow; | ||
import com.bar.evil.Evil; | ||
|
||
@Allow | ||
public class Okay { | ||
public Okay() { | ||
new Evil(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
archunit-example/src/test/java/com/bar/IgnoreByAnnotationWorksTest.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,18 @@ | ||
package com.bar; | ||
|
||
import com.tngtech.archunit.junit.AnalyzeClasses; | ||
import com.tngtech.archunit.junit.ArchTest; | ||
import com.tngtech.archunit.junit.ArchUnitRunner; | ||
import com.tngtech.archunit.lang.ArchRule; | ||
import org.junit.runner.RunWith; | ||
|
||
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses; | ||
|
||
@RunWith(ArchUnitRunner.class) | ||
@AnalyzeClasses(packages = "com.bar") | ||
public class IgnoreByAnnotationWorksTest { | ||
@ArchTest | ||
public static final ArchRule ignoring_classes_annotated_with_Allow = | ||
noClasses().that().areNotAnnotatedWith(Allow.class) | ||
.should().accessClassesThat().resideInAPackage("com.bar.evil"); | ||
} |