Skip to content

Commit 1e6dfc2

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

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
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

+70
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,6 +67,67 @@ public class CodingConventionWithSuppressionTest {
5867
*/
5968
private static final Set<Pattern> ALLOWED_ERROR_LOG_SUPPRESSION = new HashSet<>();
6069

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+
}
81+
82+
@Test
83+
void shouldNotUseFuture() {
84+
JavaClasses classes = new ClassFileImporter()
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);
91+
}
92+
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+
61131
@Test
62132
void shouldNotAbuseWarnLog() {
63133
JavaClasses classes = new ClassFileImporter()

0 commit comments

Comments
 (0)