Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
zoewangg committed Dec 18, 2024
1 parent ac08cec commit d504e8a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -150,6 +140,7 @@ void shouldNotAbuseWarnLog() {
+ " to ALLOWED_WARN_LOG_SUPPRESSION allowlist");

rule.check(classes);
System.out.println("shouldNotAbuseWarnLog finished");
}

@Test
Expand All @@ -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()
Expand All @@ -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<JavaMethod> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit d504e8a

Please sign in to comment.