Skip to content

Commit e1103fb

Browse files
committed
Use junit directly
1 parent 20366bb commit e1103fb

File tree

2 files changed

+101
-30
lines changed

2 files changed

+101
-30
lines changed

test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151

5252
@AnalyzeClasses(packages = "software.amazon.awssdk..",
5353
importOptions = ImportOption.DoNotIncludeTests.class)
54+
@ArchIgnore
5455
public class CodingConventionTest {
5556

5657
@ArchTest

test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionWithSuppressionTest.java

+100-30
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,32 @@
1515

1616
package software.amazon.awssdk.archtests;
1717

18+
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
1819
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods;
20+
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
21+
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noFields;
22+
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noMethods;
1923
import static com.tngtech.archunit.library.freeze.FreezingArchRule.freeze;
2024

2125
import com.tngtech.archunit.core.domain.JavaClasses;
2226
import com.tngtech.archunit.core.domain.JavaMethod;
27+
import com.tngtech.archunit.core.domain.JavaModifier;
2328
import com.tngtech.archunit.core.importer.ClassFileImporter;
2429
import com.tngtech.archunit.core.importer.ImportOption;
2530
import com.tngtech.archunit.junit.ArchTest;
2631
import com.tngtech.archunit.lang.ArchCondition;
2732
import com.tngtech.archunit.lang.ArchRule;
2833
import com.tngtech.archunit.lang.ConditionEvents;
2934
import com.tngtech.archunit.lang.SimpleConditionEvent;
35+
import java.io.IOException;
3036
import java.util.Arrays;
3137
import java.util.HashSet;
38+
import java.util.Optional;
3239
import java.util.Set;
40+
import java.util.concurrent.Future;
3341
import java.util.regex.Pattern;
3442
import org.junit.jupiter.api.Test;
43+
import software.amazon.awssdk.annotations.SdkPublicApi;
3544
import software.amazon.awssdk.utils.Logger;
3645

3746
/**
@@ -58,41 +67,102 @@ public class CodingConventionWithSuppressionTest {
5867
*/
5968
private static final Set<Pattern> ALLOWED_ERROR_LOG_SUPPRESSION = new HashSet<>();
6069

61-
@Test
62-
void shouldNotAbuseWarnLog() {
63-
JavaClasses classes = new ClassFileImporter()
64-
.withImportOptions(Arrays.asList(
65-
location -> ALLOWED_WARN_LOG_SUPPRESSION.stream().noneMatch(location::matches),
66-
new ImportOption.Predefined.DoNotIncludeTests()))
67-
.importPackages("software.amazon.awssdk..");
68-
69-
ArchRule rule =
70-
freeze(methods().that().areDeclaredIn(Logger.class).and()
71-
.haveName("warn").should(new MethodBeingUsedByOthers(
72-
"log.warn is detected")))
73-
.as("log.warn is detected. Review it with the team. If this is a valid case, add it"
74-
+ " to ALLOWED_WARN_LOG_SUPPRESSION allowlist");
75-
76-
rule.check(classes);
77-
}
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+
// }
7881

7982
@Test
80-
void shouldNotAbuseErrorLog() {
83+
void shouldNotUseFuture() {
8184
JavaClasses classes = new ClassFileImporter()
82-
.withImportOptions(Arrays.asList(
83-
location -> ALLOWED_ERROR_LOG_SUPPRESSION.stream().noneMatch(location::matches),
84-
new ImportOption.Predefined.DoNotIncludeTests()))
85-
.importPackages("software.amazon.awssdk..");
86-
87-
ArchRule rule =
88-
freeze(methods().that().areDeclaredIn(Logger.class).and()
89-
.haveName("error").should(new MethodBeingUsedByOthers("log.error is detected")))
90-
.as("log.error is detected. Review it with the team. If this is a valid case, add it to "
91-
+ "ALLOWED_ERROR_LOG_SUPPRESSION allowlist");
92-
93-
rule.check(classes);
85+
.withImportOptions(Arrays.asList(new ImportOption.Predefined.DoNotIncludeTests()))
86+
.importPackages("software.amazon.awssdk");
87+
freeze(noClasses().should().dependOnClassesThat().areAssignableFrom(Future.class)
88+
.as("use java.util.concurrent.Future")
89+
.because("Future SHOULD NOT be used, use CompletableFuture instead"))
90+
.check(classes);
9491
}
9592

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+
// }
165+
96166
private static final class MethodBeingUsedByOthers extends ArchCondition<JavaMethod> {
97167
public MethodBeingUsedByOthers(String description) {
98168
super(description);

0 commit comments

Comments
 (0)