@@ -67,20 +67,22 @@ public class CodingConventionWithSuppressionTest {
67
67
*/
68
68
private static final Set <Pattern > ALLOWED_ERROR_LOG_SUPPRESSION = new HashSet <>();
69
69
70
- // @Test
71
- // void publicApisShouldBeFinal() {
72
- // JavaClasses classes = new ClassFileImporter()
73
- // .withImportOptions(Arrays.asList(new ImportOption.Predefined.DoNotIncludeTests()))
74
- // .importPackages("software.amazon.awssdk");
75
- // freeze(classes().that().areAnnotatedWith(SdkPublicApi.class)
76
- // .and().areNotInterfaces()
77
- // .should().haveModifier(JavaModifier.FINAL))
78
- // .because("public APIs SHOULD be final")
79
- // .check(classes);
80
- // }
70
+ @ Test
71
+ void publicApisShouldBeFinal () {
72
+ System .out .println ("publicApisShouldBeFinal" );
73
+ JavaClasses classes = new ClassFileImporter ()
74
+ .withImportOptions (Arrays .asList (new ImportOption .Predefined .DoNotIncludeTests ()))
75
+ .importPackages ("software.amazon.awssdk" );
76
+ freeze (classes ().that ().areAnnotatedWith (SdkPublicApi .class )
77
+ .and ().areNotInterfaces ()
78
+ .should ().haveModifier (JavaModifier .FINAL ))
79
+ .because ("public APIs SHOULD be final" )
80
+ .check (classes );
81
+ }
81
82
82
83
@ Test
83
84
void shouldNotUseFuture () {
85
+ System .out .println ("shouldNotUseFuture" );
84
86
JavaClasses classes = new ClassFileImporter ()
85
87
.withImportOptions (Arrays .asList (new ImportOption .Predefined .DoNotIncludeTests ()))
86
88
.importPackages ("software.amazon.awssdk" );
@@ -90,78 +92,83 @@ void shouldNotUseFuture() {
90
92
.check (classes );
91
93
}
92
94
93
- // @Test
94
- // void shouldNotUseOptionalForFields() {
95
- // JavaClasses classes = new ClassFileImporter()
96
- // .withImportOptions(Arrays.asList(new ImportOption.Predefined.DoNotIncludeTests()))
97
- // .importPackages("software.amazon.awssdk");
98
- // freeze(noFields().should().haveRawType(Optional.class)
99
- // .as("use Optional for fields")
100
- // .because("Optional SHOULD NOT be used for method parameters. See "
101
- // + "https://github.com/aws/aws-sdk-java-v2/blob/master/docs"
102
- // + "/design/UseOfOptional.md"))
103
- // .check(classes);
104
- // }
105
- //
106
- // @Test
107
- // void mustNotUseOptionalForMethodParam() {
108
- // JavaClasses classes = new ClassFileImporter()
109
- // .withImportOptions(Arrays.asList(new ImportOption.Predefined.DoNotIncludeTests()))
110
- // .importPackages("software.amazon.awssdk");
111
- // freeze(noMethods().should().haveRawParameterTypes(Optional.class)
112
- // .as("use Optional for method parameters")
113
- // .because("Optional MUST NOT be used for method parameters. See "
114
- // + "https://github.com/aws/aws-sdk-java-v2/blob/master/docs/design/UseOfOptional.md"))
115
- // .check(classes);
116
- // }
117
- //
118
- // @Test
119
- // void publicApisMustNotDeclareThrowableOfCheckedException() {
120
- // JavaClasses classes = new ClassFileImporter()
121
- // .withImportOptions(Arrays.asList(new ImportOption.Predefined.DoNotIncludeTests()))
122
- // .importPackages("software.amazon.awssdk");
123
- // freeze(noMethods().that()
124
- // .areDeclaredInClassesThat().areAnnotatedWith(SdkPublicApi.class)
125
- // .should()
126
- // .declareThrowableOfType(Exception.class).orShould().declareThrowableOfType(IOException.class)
127
- // .because("public APIs MUST NOT throw checked exception"))
128
- // .check(classes);
129
- // }
130
- //
131
- // @Test
132
- // void shouldNotAbuseWarnLog() {
133
- // JavaClasses classes = new ClassFileImporter()
134
- // .withImportOptions(Arrays.asList(
135
- // location -> ALLOWED_WARN_LOG_SUPPRESSION.stream().noneMatch(location::matches),
136
- // new ImportOption.Predefined.DoNotIncludeTests()))
137
- // .importPackages("software.amazon.awssdk..");
138
- //
139
- // ArchRule rule =
140
- // freeze(methods().that().areDeclaredIn(Logger.class).and()
141
- // .haveName("warn").should(new MethodBeingUsedByOthers(
142
- // "log.warn is detected")))
143
- // .as("log.warn is detected. Review it with the team. If this is a valid case, add it"
144
- // + " to ALLOWED_WARN_LOG_SUPPRESSION allowlist");
145
- //
146
- // rule.check(classes);
147
- // }
148
- //
149
- // @Test
150
- // void shouldNotAbuseErrorLog() {
151
- // JavaClasses classes = new ClassFileImporter()
152
- // .withImportOptions(Arrays.asList(
153
- // location -> ALLOWED_ERROR_LOG_SUPPRESSION.stream().noneMatch(location::matches),
154
- // new ImportOption.Predefined.DoNotIncludeTests()))
155
- // .importPackages("software.amazon.awssdk..");
156
- //
157
- // ArchRule rule =
158
- // freeze(methods().that().areDeclaredIn(Logger.class).and()
159
- // .haveName("error").should(new MethodBeingUsedByOthers("log.error is detected")))
160
- // .as("log.error is detected. Review it with the team. If this is a valid case, add it to "
161
- // + "ALLOWED_ERROR_LOG_SUPPRESSION allowlist");
162
- //
163
- // rule.check(classes);
164
- // }
95
+ @ Test
96
+ void shouldNotUseOptionalForFields () {
97
+ System .out .println ("shouldNotUseOptionalForFields" );
98
+ JavaClasses classes = new ClassFileImporter ()
99
+ .withImportOptions (Arrays .asList (new ImportOption .Predefined .DoNotIncludeTests ()))
100
+ .importPackages ("software.amazon.awssdk" );
101
+ freeze (noFields ().should ().haveRawType (Optional .class )
102
+ .as ("use Optional for fields" )
103
+ .because ("Optional SHOULD NOT be used for method parameters. See "
104
+ + "https://github.com/aws/aws-sdk-java-v2/blob/master/docs"
105
+ + "/design/UseOfOptional.md" ))
106
+ .check (classes );
107
+ }
108
+
109
+ @ Test
110
+ void mustNotUseOptionalForMethodParam () {
111
+ System .out .println ("mustNotUseOptionalForMethodParam" );
112
+ JavaClasses classes = new ClassFileImporter ()
113
+ .withImportOptions (Arrays .asList (new ImportOption .Predefined .DoNotIncludeTests ()))
114
+ .importPackages ("software.amazon.awssdk" );
115
+ freeze (noMethods ().should ().haveRawParameterTypes (Optional .class )
116
+ .as ("use Optional for method parameters" )
117
+ .because ("Optional MUST NOT be used for method parameters. See "
118
+ + "https://github.com/aws/aws-sdk-java-v2/blob/master/docs/design/UseOfOptional.md" ))
119
+ .check (classes );
120
+ }
121
+
122
+ @ Test
123
+ void publicApisMustNotDeclareThrowableOfCheckedException () {
124
+ System .out .println ("publicApisMustNotDeclareThrowableOfCheckedException" );
125
+ JavaClasses classes = new ClassFileImporter ()
126
+ .withImportOptions (Arrays .asList (new ImportOption .Predefined .DoNotIncludeTests ()))
127
+ .importPackages ("software.amazon.awssdk" );
128
+ freeze (noMethods ().that ()
129
+ .areDeclaredInClassesThat ().areAnnotatedWith (SdkPublicApi .class )
130
+ .should ()
131
+ .declareThrowableOfType (Exception .class ).orShould ().declareThrowableOfType (IOException .class )
132
+ .because ("public APIs MUST NOT throw checked exception" ))
133
+ .check (classes );
134
+ }
135
+
136
+ @ Test
137
+ void shouldNotAbuseWarnLog () {
138
+ System .out .println ("shouldNotAbuseWarnLog" );
139
+ JavaClasses classes = new ClassFileImporter ()
140
+ .withImportOptions (Arrays .asList (
141
+ location -> ALLOWED_WARN_LOG_SUPPRESSION .stream ().noneMatch (location ::matches ),
142
+ new ImportOption .Predefined .DoNotIncludeTests ()))
143
+ .importPackages ("software.amazon.awssdk.." );
144
+
145
+ ArchRule rule =
146
+ freeze (methods ().that ().areDeclaredIn (Logger .class ).and ()
147
+ .haveName ("warn" ).should (new MethodBeingUsedByOthers (
148
+ "log.warn is detected" )))
149
+ .as ("log.warn is detected. Review it with the team. If this is a valid case, add it"
150
+ + " to ALLOWED_WARN_LOG_SUPPRESSION allowlist" );
151
+
152
+ rule .check (classes );
153
+ }
154
+
155
+ @ Test
156
+ void shouldNotAbuseErrorLog () {
157
+ System .out .println ("shouldNotAbuseErrorLog" );
158
+ JavaClasses classes = new ClassFileImporter ()
159
+ .withImportOptions (Arrays .asList (
160
+ location -> ALLOWED_ERROR_LOG_SUPPRESSION .stream ().noneMatch (location ::matches ),
161
+ new ImportOption .Predefined .DoNotIncludeTests ()))
162
+ .importPackages ("software.amazon.awssdk.." );
163
+
164
+ ArchRule rule =
165
+ freeze (methods ().that ().areDeclaredIn (Logger .class ).and ()
166
+ .haveName ("error" ).should (new MethodBeingUsedByOthers ("log.error is detected" )))
167
+ .as ("log.error is detected. Review it with the team. If this is a valid case, add it to "
168
+ + "ALLOWED_ERROR_LOG_SUPPRESSION allowlist" );
169
+
170
+ rule .check (classes );
171
+ }
165
172
166
173
private static final class MethodBeingUsedByOthers extends ArchCondition <JavaMethod > {
167
174
public MethodBeingUsedByOthers (String description ) {
0 commit comments