Skip to content

Commit 052069a

Browse files
SirCotareclaude
andcommitted
add a red/green fixture test for every shipped rule
Each of the 13 rules gets a fixture built to violate it and one built to satisfy it, asserted on the violation count and message rather than on the rule having run. The library had no such test, which is why rules that match nothing have been reporting success. This commit is deliberately red: nine tests fail. Eight fixtures that must produce a violation do not. - test classes with no production counterpart (rule is fully dead) - a blacklisted annotation on a constructor parameter - a blacklisted method call from a constructor - a blacklisted method call from an instance field initializer - System.out from a constructor - a @nested test class whose production class is missing entirely - a controller method covered only by a longer-named sibling's @nested class - a non-static SortMappings field The ninth is not a fixture: the blacklist names three AssertJ methods that do not exist, so those entries can never match. Fixtures live outside it.aboutbits.archunit.toolbox so the project's own ArchitectureTest does not analyse them, and are excluded from surefire because some are named *Test. Third-party types the blacklists name are stubbed rather than depended on: spring-boot-toolbox depends on archunit-toolbox, so SortMappings, @Store and @ArchAllowDirectAccess cannot come from there. The stub contracts were verified against the real 2.5.2 artifact. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 8aee4f1 commit 052069a

82 files changed

Lines changed: 1367 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pom.xml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,32 @@
5050
<version>1.4.2</version>
5151
<scope>compile</scope>
5252
</dependency>
53+
54+
<!-- Test only: needed to run this library's own rule tests -->
55+
<dependency>
56+
<groupId>org.junit.jupiter</groupId>
57+
<artifactId>junit-jupiter-engine</artifactId>
58+
<scope>test</scope>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.assertj</groupId>
62+
<artifactId>assertj-core</artifactId>
63+
<scope>test</scope>
64+
</dependency>
65+
<!--
66+
Fixtures for the two rules in CommonArchRuleCollection need real Spring MVC annotations.
67+
Test scope only, so consumers do not inherit them.
68+
-->
69+
<dependency>
70+
<groupId>org.springframework</groupId>
71+
<artifactId>spring-web</artifactId>
72+
<scope>test</scope>
73+
</dependency>
74+
<dependency>
75+
<groupId>org.springframework</groupId>
76+
<artifactId>spring-context</artifactId>
77+
<scope>test</scope>
78+
</dependency>
5379
</dependencies>
5480

5581
<build>
@@ -98,6 +124,20 @@
98124
<fork>true</fork>
99125
</configuration>
100126
</plugin>
127+
<plugin>
128+
<groupId>org.apache.maven.plugins</groupId>
129+
<artifactId>maven-surefire-plugin</artifactId>
130+
<configuration>
131+
<!--
132+
it.aboutbits.archunit.fixture contains deliberately non-conforming classes that
133+
the rule tests import as input. Some are named *Test and would otherwise be
134+
collected and reported as tests of this project.
135+
-->
136+
<excludes>
137+
<exclude>it/aboutbits/archunit/fixture/**</exclude>
138+
</excludes>
139+
</configuration>
140+
</plugin>
101141
<plugin>
102142
<groupId>org.apache.maven.plugins</groupId>
103143
<artifactId>maven-checkstyle-plugin</artifactId>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package it.aboutbits.archunit.fixture.barren;
2+
3+
import org.jspecify.annotations.NullMarked;
4+
5+
/**
6+
* A codebase with no test classes, no records, no controllers and no stores. Used to pin that a rule
7+
* whose selection comes up empty fails instead of reporting success.
8+
*/
9+
@NullMarked
10+
public class PlainClass {
11+
public String value() {
12+
return "value";
13+
}
14+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package it.aboutbits.archunit.fixture.blacklistannotations.badclass;
2+
3+
@org.junit.Ignore
4+
public class AnnotatedClass {
5+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package it.aboutbits.archunit.fixture.blacklistannotations.badctorparam;
2+
3+
/** The canonical Lombok position, and the one a rule iterating only getMethods() cannot see. */
4+
public class AnnotatedConstructorParameter {
5+
private final String value;
6+
7+
public AnnotatedConstructorParameter(@lombok.NonNull String value) {
8+
this.value = value;
9+
}
10+
11+
public String value() {
12+
return value;
13+
}
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package it.aboutbits.archunit.fixture.blacklistannotations.badfield;
2+
3+
public class AnnotatedField {
4+
@lombok.NonNull
5+
private String value = "x";
6+
7+
public String value() {
8+
return value;
9+
}
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package it.aboutbits.archunit.fixture.blacklistannotations.badmethod;
2+
3+
public class AnnotatedMethod {
4+
@org.junit.Ignore
5+
public void doWork() {
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package it.aboutbits.archunit.fixture.blacklistannotations.badparam;
2+
3+
public class AnnotatedParameter {
4+
public void doWork(@lombok.NonNull String value) {
5+
System.identityHashCode(value);
6+
}
7+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package it.aboutbits.archunit.fixture.blacklistannotations.good;
2+
3+
public class CleanClass {
4+
private String value = "x";
5+
6+
public void doWork(String input) {
7+
this.value = input;
8+
}
9+
10+
public String value() {
11+
return value;
12+
}
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package it.aboutbits.archunit.fixture.blacklistclasses.bad;
2+
3+
import net.datafaker.Faker;
4+
5+
public class UsesFaker {
6+
public String randomName() {
7+
return new Faker().name();
8+
}
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package it.aboutbits.archunit.fixture.blacklistclasses.good;
2+
3+
public class UsesNothingBlacklisted {
4+
public String randomName() {
5+
return "fixed";
6+
}
7+
}

0 commit comments

Comments
 (0)