2121class ArchitectureRulesTest {
2222 private static final String BROKEN_CLASS_NAME = ArchitectureRulesViolatedTest .class .getTypeName ();
2323
24+ @ Test
25+ void shouldVerifyThatFieldsArePrivate () {
26+ assertThatExceptionOfType (AssertionError .class ).isThrownBy (
27+ () -> ArchitectureRules .ONLY_PRIVATE_FIELDS .check (importBrokenClass ()))
28+ .withMessageContainingAll (BROKEN_CLASS_NAME , "fields that do not have modifier STATIC should be private' was violated" );
29+
30+ assertThatNoException ().isThrownBy (
31+ () -> ArchitectureRules .ONLY_PRIVATE_FIELDS .check (importPassingClass ()));
32+ }
33+
2434 @ Test
2535 void shouldUseProtectedForReadResolve () {
2636 assertThatExceptionOfType (AssertionError .class ).isThrownBy (
@@ -100,7 +110,7 @@ void shouldVerifyNoPublicTestMethodsRule() {
100110
101111 private JavaClasses importPassingClass () {
102112 return new ClassFileImporter ().importClasses (ArchitectureRulesPassedTest .class ,
103- ArchitectureRulesAlsoPassedTest .class );
113+ ArchitectureRulesAlsoPassedTest .class , ArchitectureRulesPassed . class );
104114 }
105115
106116 private JavaClasses importBrokenClass () {
@@ -117,6 +127,8 @@ public static class ArchitectureRulesViolatedTest {
117127 @ edu .umd .cs .findbugs .annotations .Nullable
118128 private final String noNullable = null ;
119129
130+ int nonPrivate ;
131+
120132 @ Test @ Disabled ("This test is just there to be used in architecture tests" )
121133 public void shouldFail () {
122134 org .junit .jupiter .api .Assertions .assertEquals (1 , 1 );
@@ -188,4 +200,9 @@ protected Object readResolve() {
188200 return this ;
189201 }
190202 }
203+
204+ @ SuppressWarnings ("all" ) // This class is just there to be used in architecture tests
205+ static class ArchitectureRulesPassed {
206+ private int privateField ;
207+ }
191208}
0 commit comments