From e7f154dbcae387853a38175f25ccf8848984fa2d Mon Sep 17 00:00:00 2001 From: Zoe Wang <33073555+zoewangg@users.noreply.github.com> Date: Wed, 11 Dec 2024 15:09:13 -0800 Subject: [PATCH 1/5] Re-enable coding convention tests --- .../software/amazon/awssdk/archtests/CodingConventionTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionTest.java b/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionTest.java index dff17d97bfa..8588fab45c2 100644 --- a/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionTest.java +++ b/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionTest.java @@ -49,7 +49,6 @@ import software.amazon.awssdk.annotations.SdkPublicApi; @AnalyzeClasses(packages = "software.amazon.awssdk..") -@ArchIgnore(reason = "CI keeps crashing when running the tests. Ignoring them for now") public class CodingConventionTest { @ArchTest From 20366bb7692e5f53778ba99d22995fa5938d3b16 Mon Sep 17 00:00:00 2001 From: Zoe Wang <33073555+zoewangg@users.noreply.github.com> Date: Thu, 12 Dec 2024 11:27:43 -0800 Subject: [PATCH 2/5] Ignore some of the less critical convenstions to see if it helps --- .../amazon/awssdk/archtests/CodingConventionTest.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionTest.java b/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionTest.java index 8588fab45c2..87d2628c512 100644 --- a/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionTest.java +++ b/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionTest.java @@ -33,6 +33,7 @@ import com.tngtech.archunit.core.domain.JavaMethod; import com.tngtech.archunit.core.domain.JavaModifier; import com.tngtech.archunit.core.domain.JavaParameter; +import com.tngtech.archunit.core.importer.ImportOption; import com.tngtech.archunit.junit.AnalyzeClasses; import com.tngtech.archunit.junit.ArchIgnore; import com.tngtech.archunit.junit.ArchTest; @@ -48,7 +49,8 @@ import software.amazon.awssdk.annotations.SdkProtectedApi; import software.amazon.awssdk.annotations.SdkPublicApi; -@AnalyzeClasses(packages = "software.amazon.awssdk..") +@AnalyzeClasses(packages = "software.amazon.awssdk..", + importOptions = ImportOption.DoNotIncludeTests.class) public class CodingConventionTest { @ArchTest @@ -59,10 +61,12 @@ public class CodingConventionTest { .because("public APIs SHOULD be final"); @ArchTest + @ArchIgnore(reason = "Ignoring it for now to avoid tests crashing") static final ArchRule mustNotUseJavaLogging = NO_CLASSES_SHOULD_USE_JAVA_UTIL_LOGGING; @ArchTest + @ArchIgnore(reason = "Ignoring it for now to avoid tests crashing") static final ArchRule mustNotUseSlfLoggerDirectly = freeze(noClasses().should(setFieldWhere(assignableFrom(org.slf4j.Logger.class) .onResultOf(JavaAccess.Functions.Get. Date: Thu, 12 Dec 2024 13:10:42 -0800 Subject: [PATCH 3/5] Use junit directly --- .../archtests/CodingConventionTest.java | 1 + .../CodingConventionWithSuppressionTest.java | 130 ++++++++++++++---- 2 files changed, 101 insertions(+), 30 deletions(-) diff --git a/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionTest.java b/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionTest.java index 87d2628c512..1c05dd5b1ac 100644 --- a/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionTest.java +++ b/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionTest.java @@ -51,6 +51,7 @@ @AnalyzeClasses(packages = "software.amazon.awssdk..", importOptions = ImportOption.DoNotIncludeTests.class) +@ArchIgnore public class CodingConventionTest { @ArchTest diff --git a/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionWithSuppressionTest.java b/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionWithSuppressionTest.java index 8259a12ca0d..2a1a24f73ab 100644 --- a/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionWithSuppressionTest.java +++ b/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionWithSuppressionTest.java @@ -15,11 +15,16 @@ package software.amazon.awssdk.archtests; +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods; +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses; +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noFields; +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noMethods; import static com.tngtech.archunit.library.freeze.FreezingArchRule.freeze; import com.tngtech.archunit.core.domain.JavaClasses; import com.tngtech.archunit.core.domain.JavaMethod; +import com.tngtech.archunit.core.domain.JavaModifier; import com.tngtech.archunit.core.importer.ClassFileImporter; import com.tngtech.archunit.core.importer.ImportOption; import com.tngtech.archunit.junit.ArchTest; @@ -27,11 +32,15 @@ import com.tngtech.archunit.lang.ArchRule; import com.tngtech.archunit.lang.ConditionEvents; import com.tngtech.archunit.lang.SimpleConditionEvent; +import java.io.IOException; import java.util.Arrays; import java.util.HashSet; +import java.util.Optional; import java.util.Set; +import java.util.concurrent.Future; import java.util.regex.Pattern; import org.junit.jupiter.api.Test; +import software.amazon.awssdk.annotations.SdkPublicApi; import software.amazon.awssdk.utils.Logger; /** @@ -58,41 +67,102 @@ public class CodingConventionWithSuppressionTest { */ private static final Set ALLOWED_ERROR_LOG_SUPPRESSION = new HashSet<>(); - @Test - void shouldNotAbuseWarnLog() { - JavaClasses classes = new ClassFileImporter() - .withImportOptions(Arrays.asList( - location -> ALLOWED_WARN_LOG_SUPPRESSION.stream().noneMatch(location::matches), - new ImportOption.Predefined.DoNotIncludeTests())) - .importPackages("software.amazon.awssdk.."); - - ArchRule rule = - freeze(methods().that().areDeclaredIn(Logger.class).and() - .haveName("warn").should(new MethodBeingUsedByOthers( - "log.warn is detected"))) - .as("log.warn is detected. Review it with the team. If this is a valid case, add it" - + " to ALLOWED_WARN_LOG_SUPPRESSION allowlist"); - - rule.check(classes); - } + // @Test + // void publicApisShouldBeFinal() { + // JavaClasses classes = new ClassFileImporter() + // .withImportOptions(Arrays.asList(new ImportOption.Predefined.DoNotIncludeTests())) + // .importPackages("software.amazon.awssdk"); + // freeze(classes().that().areAnnotatedWith(SdkPublicApi.class) + // .and().areNotInterfaces() + // .should().haveModifier(JavaModifier.FINAL)) + // .because("public APIs SHOULD be final") + // .check(classes); + // } @Test - void shouldNotAbuseErrorLog() { + void shouldNotUseFuture() { JavaClasses classes = new ClassFileImporter() - .withImportOptions(Arrays.asList( - location -> ALLOWED_ERROR_LOG_SUPPRESSION.stream().noneMatch(location::matches), - new ImportOption.Predefined.DoNotIncludeTests())) - .importPackages("software.amazon.awssdk.."); - - ArchRule rule = - freeze(methods().that().areDeclaredIn(Logger.class).and() - .haveName("error").should(new MethodBeingUsedByOthers("log.error is detected"))) - .as("log.error is detected. Review it with the team. If this is a valid case, add it to " - + "ALLOWED_ERROR_LOG_SUPPRESSION allowlist"); - - rule.check(classes); + .withImportOptions(Arrays.asList(new ImportOption.Predefined.DoNotIncludeTests())) + .importPackages("software.amazon.awssdk"); + freeze(noClasses().should().dependOnClassesThat().areAssignableFrom(Future.class) + .as("use java.util.concurrent.Future") + .because("Future SHOULD NOT be used, use CompletableFuture instead")) + .check(classes); } + // @Test + // void shouldNotUseOptionalForFields() { + // JavaClasses classes = new ClassFileImporter() + // .withImportOptions(Arrays.asList(new ImportOption.Predefined.DoNotIncludeTests())) + // .importPackages("software.amazon.awssdk"); + // freeze(noFields().should().haveRawType(Optional.class) + // .as("use Optional for fields") + // .because("Optional SHOULD NOT be used for method parameters. See " + // + "https://github.com/aws/aws-sdk-java-v2/blob/master/docs" + // + "/design/UseOfOptional.md")) + // .check(classes); + // } + // + // @Test + // void mustNotUseOptionalForMethodParam() { + // JavaClasses classes = new ClassFileImporter() + // .withImportOptions(Arrays.asList(new ImportOption.Predefined.DoNotIncludeTests())) + // .importPackages("software.amazon.awssdk"); + // freeze(noMethods().should().haveRawParameterTypes(Optional.class) + // .as("use Optional for method parameters") + // .because("Optional MUST NOT be used for method parameters. See " + // + "https://github.com/aws/aws-sdk-java-v2/blob/master/docs/design/UseOfOptional.md")) + // .check(classes); + // } + // + // @Test + // void publicApisMustNotDeclareThrowableOfCheckedException() { + // JavaClasses classes = new ClassFileImporter() + // .withImportOptions(Arrays.asList(new ImportOption.Predefined.DoNotIncludeTests())) + // .importPackages("software.amazon.awssdk"); + // freeze(noMethods().that() + // .areDeclaredInClassesThat().areAnnotatedWith(SdkPublicApi.class) + // .should() + // .declareThrowableOfType(Exception.class).orShould().declareThrowableOfType(IOException.class) + // .because("public APIs MUST NOT throw checked exception")) + // .check(classes); + // } + // + // @Test + // void shouldNotAbuseWarnLog() { + // JavaClasses classes = new ClassFileImporter() + // .withImportOptions(Arrays.asList( + // location -> ALLOWED_WARN_LOG_SUPPRESSION.stream().noneMatch(location::matches), + // new ImportOption.Predefined.DoNotIncludeTests())) + // .importPackages("software.amazon.awssdk.."); + // + // ArchRule rule = + // freeze(methods().that().areDeclaredIn(Logger.class).and() + // .haveName("warn").should(new MethodBeingUsedByOthers( + // "log.warn is detected"))) + // .as("log.warn is detected. Review it with the team. If this is a valid case, add it" + // + " to ALLOWED_WARN_LOG_SUPPRESSION allowlist"); + // + // rule.check(classes); + // } + // + // @Test + // void shouldNotAbuseErrorLog() { + // JavaClasses classes = new ClassFileImporter() + // .withImportOptions(Arrays.asList( + // location -> ALLOWED_ERROR_LOG_SUPPRESSION.stream().noneMatch(location::matches), + // new ImportOption.Predefined.DoNotIncludeTests())) + // .importPackages("software.amazon.awssdk.."); + // + // ArchRule rule = + // freeze(methods().that().areDeclaredIn(Logger.class).and() + // .haveName("error").should(new MethodBeingUsedByOthers("log.error is detected"))) + // .as("log.error is detected. Review it with the team. If this is a valid case, add it to " + // + "ALLOWED_ERROR_LOG_SUPPRESSION allowlist"); + // + // rule.check(classes); + // } + private static final class MethodBeingUsedByOthers extends ArchCondition { public MethodBeingUsedByOthers(String description) { super(description); From cc72c69a37989fa0eb3ddf0dbb5de5f4cf37cb27 Mon Sep 17 00:00:00 2001 From: Zoe Wang <33073555+zoewangg@users.noreply.github.com> Date: Thu, 12 Dec 2024 15:36:30 -0800 Subject: [PATCH 4/5] Test --- .../CodingConventionWithSuppressionTest.java | 173 +++++++++--------- 1 file changed, 90 insertions(+), 83 deletions(-) diff --git a/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionWithSuppressionTest.java b/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionWithSuppressionTest.java index 2a1a24f73ab..a117aaec855 100644 --- a/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionWithSuppressionTest.java +++ b/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionWithSuppressionTest.java @@ -67,20 +67,22 @@ public class CodingConventionWithSuppressionTest { */ private static final Set ALLOWED_ERROR_LOG_SUPPRESSION = new HashSet<>(); - // @Test - // void publicApisShouldBeFinal() { - // JavaClasses classes = new ClassFileImporter() - // .withImportOptions(Arrays.asList(new ImportOption.Predefined.DoNotIncludeTests())) - // .importPackages("software.amazon.awssdk"); - // freeze(classes().that().areAnnotatedWith(SdkPublicApi.class) - // .and().areNotInterfaces() - // .should().haveModifier(JavaModifier.FINAL)) - // .because("public APIs SHOULD be final") - // .check(classes); - // } + @Test + void publicApisShouldBeFinal() { + System.out.println("publicApisShouldBeFinal"); + JavaClasses classes = new ClassFileImporter() + .withImportOptions(Arrays.asList(new ImportOption.Predefined.DoNotIncludeTests())) + .importPackages("software.amazon.awssdk"); + freeze(classes().that().areAnnotatedWith(SdkPublicApi.class) + .and().areNotInterfaces() + .should().haveModifier(JavaModifier.FINAL)) + .because("public APIs SHOULD be final") + .check(classes); + } @Test void shouldNotUseFuture() { + System.out.println("shouldNotUseFuture"); JavaClasses classes = new ClassFileImporter() .withImportOptions(Arrays.asList(new ImportOption.Predefined.DoNotIncludeTests())) .importPackages("software.amazon.awssdk"); @@ -90,78 +92,83 @@ void shouldNotUseFuture() { .check(classes); } - // @Test - // void shouldNotUseOptionalForFields() { - // JavaClasses classes = new ClassFileImporter() - // .withImportOptions(Arrays.asList(new ImportOption.Predefined.DoNotIncludeTests())) - // .importPackages("software.amazon.awssdk"); - // freeze(noFields().should().haveRawType(Optional.class) - // .as("use Optional for fields") - // .because("Optional SHOULD NOT be used for method parameters. See " - // + "https://github.com/aws/aws-sdk-java-v2/blob/master/docs" - // + "/design/UseOfOptional.md")) - // .check(classes); - // } - // - // @Test - // void mustNotUseOptionalForMethodParam() { - // JavaClasses classes = new ClassFileImporter() - // .withImportOptions(Arrays.asList(new ImportOption.Predefined.DoNotIncludeTests())) - // .importPackages("software.amazon.awssdk"); - // freeze(noMethods().should().haveRawParameterTypes(Optional.class) - // .as("use Optional for method parameters") - // .because("Optional MUST NOT be used for method parameters. See " - // + "https://github.com/aws/aws-sdk-java-v2/blob/master/docs/design/UseOfOptional.md")) - // .check(classes); - // } - // - // @Test - // void publicApisMustNotDeclareThrowableOfCheckedException() { - // JavaClasses classes = new ClassFileImporter() - // .withImportOptions(Arrays.asList(new ImportOption.Predefined.DoNotIncludeTests())) - // .importPackages("software.amazon.awssdk"); - // freeze(noMethods().that() - // .areDeclaredInClassesThat().areAnnotatedWith(SdkPublicApi.class) - // .should() - // .declareThrowableOfType(Exception.class).orShould().declareThrowableOfType(IOException.class) - // .because("public APIs MUST NOT throw checked exception")) - // .check(classes); - // } - // - // @Test - // void shouldNotAbuseWarnLog() { - // JavaClasses classes = new ClassFileImporter() - // .withImportOptions(Arrays.asList( - // location -> ALLOWED_WARN_LOG_SUPPRESSION.stream().noneMatch(location::matches), - // new ImportOption.Predefined.DoNotIncludeTests())) - // .importPackages("software.amazon.awssdk.."); - // - // ArchRule rule = - // freeze(methods().that().areDeclaredIn(Logger.class).and() - // .haveName("warn").should(new MethodBeingUsedByOthers( - // "log.warn is detected"))) - // .as("log.warn is detected. Review it with the team. If this is a valid case, add it" - // + " to ALLOWED_WARN_LOG_SUPPRESSION allowlist"); - // - // rule.check(classes); - // } - // - // @Test - // void shouldNotAbuseErrorLog() { - // JavaClasses classes = new ClassFileImporter() - // .withImportOptions(Arrays.asList( - // location -> ALLOWED_ERROR_LOG_SUPPRESSION.stream().noneMatch(location::matches), - // new ImportOption.Predefined.DoNotIncludeTests())) - // .importPackages("software.amazon.awssdk.."); - // - // ArchRule rule = - // freeze(methods().that().areDeclaredIn(Logger.class).and() - // .haveName("error").should(new MethodBeingUsedByOthers("log.error is detected"))) - // .as("log.error is detected. Review it with the team. If this is a valid case, add it to " - // + "ALLOWED_ERROR_LOG_SUPPRESSION allowlist"); - // - // rule.check(classes); - // } + @Test + void shouldNotUseOptionalForFields() { + System.out.println("shouldNotUseOptionalForFields"); + JavaClasses classes = new ClassFileImporter() + .withImportOptions(Arrays.asList(new ImportOption.Predefined.DoNotIncludeTests())) + .importPackages("software.amazon.awssdk"); + freeze(noFields().should().haveRawType(Optional.class) + .as("use Optional for fields") + .because("Optional SHOULD NOT be used for method parameters. See " + + "https://github.com/aws/aws-sdk-java-v2/blob/master/docs" + + "/design/UseOfOptional.md")) + .check(classes); + } + + @Test + void mustNotUseOptionalForMethodParam() { + System.out.println("mustNotUseOptionalForMethodParam"); + JavaClasses classes = new ClassFileImporter() + .withImportOptions(Arrays.asList(new ImportOption.Predefined.DoNotIncludeTests())) + .importPackages("software.amazon.awssdk"); + freeze(noMethods().should().haveRawParameterTypes(Optional.class) + .as("use Optional for method parameters") + .because("Optional MUST NOT be used for method parameters. See " + + "https://github.com/aws/aws-sdk-java-v2/blob/master/docs/design/UseOfOptional.md")) + .check(classes); + } + + @Test + void publicApisMustNotDeclareThrowableOfCheckedException() { + System.out.println("publicApisMustNotDeclareThrowableOfCheckedException"); + JavaClasses classes = new ClassFileImporter() + .withImportOptions(Arrays.asList(new ImportOption.Predefined.DoNotIncludeTests())) + .importPackages("software.amazon.awssdk"); + freeze(noMethods().that() + .areDeclaredInClassesThat().areAnnotatedWith(SdkPublicApi.class) + .should() + .declareThrowableOfType(Exception.class).orShould().declareThrowableOfType(IOException.class) + .because("public APIs MUST NOT throw checked exception")) + .check(classes); + } + + @Test + void shouldNotAbuseWarnLog() { + System.out.println("shouldNotAbuseWarnLog"); + JavaClasses classes = new ClassFileImporter() + .withImportOptions(Arrays.asList( + location -> ALLOWED_WARN_LOG_SUPPRESSION.stream().noneMatch(location::matches), + new ImportOption.Predefined.DoNotIncludeTests())) + .importPackages("software.amazon.awssdk.."); + + ArchRule rule = + freeze(methods().that().areDeclaredIn(Logger.class).and() + .haveName("warn").should(new MethodBeingUsedByOthers( + "log.warn is detected"))) + .as("log.warn is detected. Review it with the team. If this is a valid case, add it" + + " to ALLOWED_WARN_LOG_SUPPRESSION allowlist"); + + rule.check(classes); + } + + @Test + void shouldNotAbuseErrorLog() { + System.out.println("shouldNotAbuseErrorLog"); + JavaClasses classes = new ClassFileImporter() + .withImportOptions(Arrays.asList( + location -> ALLOWED_ERROR_LOG_SUPPRESSION.stream().noneMatch(location::matches), + new ImportOption.Predefined.DoNotIncludeTests())) + .importPackages("software.amazon.awssdk.."); + + ArchRule rule = + freeze(methods().that().areDeclaredIn(Logger.class).and() + .haveName("error").should(new MethodBeingUsedByOthers("log.error is detected"))) + .as("log.error is detected. Review it with the team. If this is a valid case, add it to " + + "ALLOWED_ERROR_LOG_SUPPRESSION allowlist"); + + rule.check(classes); + } private static final class MethodBeingUsedByOthers extends ArchCondition { public MethodBeingUsedByOthers(String description) { From ac2ca0399b1e6cd3bd0e6ea38eaa29a6a4967544 Mon Sep 17 00:00:00 2001 From: Zoe Wang <33073555+zoewangg@users.noreply.github.com> Date: Thu, 12 Dec 2024 18:50:11 -0800 Subject: [PATCH 5/5] Test --- test/architecture-tests/pom.xml | 16 ++++++++++++ .../archtests/CodingConventionTest.java | 2 +- .../CodingConventionWithSuppressionTest.java | 26 +++++++------------ .../archtests/NamingConventionTest.java | 7 +---- .../NamingConventionWithSuppressionTest.java | 2 +- 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/test/architecture-tests/pom.xml b/test/architecture-tests/pom.xml index dba065dc63b..724054c03ea 100644 --- a/test/architecture-tests/pom.xml +++ b/test/architecture-tests/pom.xml @@ -193,6 +193,22 @@ true + + org.apache.maven.plugins + maven-surefire-plugin + ${maven.surefire.version} + + -XX:MaxMetaspaceSize=1g -Xmx5120m + 0 + + **/Test*.java + **/*Tests.java + **/*Test.java + **/*TestCase.java + + ${skip.unit.tests} + + \ No newline at end of file diff --git a/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionTest.java b/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionTest.java index 1c05dd5b1ac..34754e18d7c 100644 --- a/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionTest.java +++ b/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionTest.java @@ -49,7 +49,7 @@ import software.amazon.awssdk.annotations.SdkProtectedApi; import software.amazon.awssdk.annotations.SdkPublicApi; -@AnalyzeClasses(packages = "software.amazon.awssdk..", +@AnalyzeClasses(packages = "software.amazon.awssdk", importOptions = ImportOption.DoNotIncludeTests.class) @ArchIgnore public class CodingConventionTest { diff --git a/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionWithSuppressionTest.java b/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionWithSuppressionTest.java index a117aaec855..0d132d85552 100644 --- a/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionWithSuppressionTest.java +++ b/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/CodingConventionWithSuppressionTest.java @@ -17,7 +17,6 @@ import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods; -import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses; import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noFields; import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noMethods; import static com.tngtech.archunit.library.freeze.FreezingArchRule.freeze; @@ -37,7 +36,6 @@ import java.util.HashSet; import java.util.Optional; import java.util.Set; -import java.util.concurrent.Future; import java.util.regex.Pattern; import org.junit.jupiter.api.Test; import software.amazon.awssdk.annotations.SdkPublicApi; @@ -78,18 +76,7 @@ void publicApisShouldBeFinal() { .should().haveModifier(JavaModifier.FINAL)) .because("public APIs SHOULD be final") .check(classes); - } - - @Test - void shouldNotUseFuture() { - System.out.println("shouldNotUseFuture"); - JavaClasses classes = new ClassFileImporter() - .withImportOptions(Arrays.asList(new ImportOption.Predefined.DoNotIncludeTests())) - .importPackages("software.amazon.awssdk"); - freeze(noClasses().should().dependOnClassesThat().areAssignableFrom(Future.class) - .as("use java.util.concurrent.Future") - .because("Future SHOULD NOT be used, use CompletableFuture instead")) - .check(classes); + System.out.println("publicApisShouldBeFinal finished"); } @Test @@ -104,6 +91,7 @@ void shouldNotUseOptionalForFields() { + "https://github.com/aws/aws-sdk-java-v2/blob/master/docs" + "/design/UseOfOptional.md")) .check(classes); + System.out.println("shouldNotUseOptionalForFields finished"); } @Test @@ -117,6 +105,7 @@ void mustNotUseOptionalForMethodParam() { .because("Optional MUST NOT be used for method parameters. See " + "https://github.com/aws/aws-sdk-java-v2/blob/master/docs/design/UseOfOptional.md")) .check(classes); + System.out.println("mustNotUseOptionalForMethodParam finished"); } @Test @@ -125,12 +114,13 @@ void publicApisMustNotDeclareThrowableOfCheckedException() { JavaClasses classes = new ClassFileImporter() .withImportOptions(Arrays.asList(new ImportOption.Predefined.DoNotIncludeTests())) .importPackages("software.amazon.awssdk"); - freeze(noMethods().that() + freeze(noMethods().that().arePublic().and() .areDeclaredInClassesThat().areAnnotatedWith(SdkPublicApi.class) .should() .declareThrowableOfType(Exception.class).orShould().declareThrowableOfType(IOException.class) .because("public APIs MUST NOT throw checked exception")) .check(classes); + System.out.println("publicApisMustNotDeclareThrowableOfCheckedException finished"); } @Test @@ -140,7 +130,7 @@ void shouldNotAbuseWarnLog() { .withImportOptions(Arrays.asList( location -> ALLOWED_WARN_LOG_SUPPRESSION.stream().noneMatch(location::matches), new ImportOption.Predefined.DoNotIncludeTests())) - .importPackages("software.amazon.awssdk.."); + .importPackages("software.amazon.awssdk"); ArchRule rule = freeze(methods().that().areDeclaredIn(Logger.class).and() @@ -150,6 +140,7 @@ void shouldNotAbuseWarnLog() { + " to ALLOWED_WARN_LOG_SUPPRESSION allowlist"); rule.check(classes); + System.out.println("shouldNotAbuseWarnLog finished"); } @Test @@ -159,7 +150,7 @@ void shouldNotAbuseErrorLog() { .withImportOptions(Arrays.asList( location -> ALLOWED_ERROR_LOG_SUPPRESSION.stream().noneMatch(location::matches), new ImportOption.Predefined.DoNotIncludeTests())) - .importPackages("software.amazon.awssdk.."); + .importPackages("software.amazon.awssdk"); ArchRule rule = freeze(methods().that().areDeclaredIn(Logger.class).and() @@ -168,6 +159,7 @@ void shouldNotAbuseErrorLog() { + "ALLOWED_ERROR_LOG_SUPPRESSION allowlist"); rule.check(classes); + System.out.println("shouldNotAbuseErrorLog finished"); } private static final class MethodBeingUsedByOthers extends ArchCondition { diff --git a/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/NamingConventionTest.java b/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/NamingConventionTest.java index 65460c2cd7b..0d9e4e26ac7 100644 --- a/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/NamingConventionTest.java +++ b/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/NamingConventionTest.java @@ -22,14 +22,9 @@ import com.tngtech.archunit.junit.AnalyzeClasses; import com.tngtech.archunit.junit.ArchTest; import com.tngtech.archunit.lang.ArchRule; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; -import java.util.function.Supplier; -import java.util.regex.Pattern; import software.amazon.awssdk.awscore.presigner.SdkPresigner; -@AnalyzeClasses(packages = "software.amazon.awssdk..") +@AnalyzeClasses(packages = "software.amazon.awssdk") public class NamingConventionTest { @ArchTest diff --git a/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/NamingConventionWithSuppressionTest.java b/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/NamingConventionWithSuppressionTest.java index 75277418c19..e9299103d11 100644 --- a/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/NamingConventionWithSuppressionTest.java +++ b/test/architecture-tests/src/test/java/software/amazon/awssdk/archtests/NamingConventionWithSuppressionTest.java @@ -54,7 +54,7 @@ void supplierImpl_shouldHaveSupplierSuffix() { .withImportOptions(Arrays.asList( location -> ALLOWED_SUPPLIER_SUPPRESSION.stream().noneMatch(location::matches), new ImportOption.Predefined.DoNotIncludeTests())) - .importPackages("software.amazon.awssdk.."); + .importPackages("software.amazon.awssdk"); ArchRule rule = classes().that().implement(Supplier.class).and().areNotPackagePrivate().should().haveSimpleNameEndingWith(