Skip to content

Commit

Permalink
feat : add more coding rules
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Jul 14, 2024
1 parent 801019e commit 9022c64
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class ArchitectureConstants {
// Packages
public static final String CONTROLLER_PACKAGE = "..controllers..";
public static final String MODEL_PACKAGE = "..model..";
public static final String ENTITY_PACKAGE = "..entities..";
public static final String MAPPER_PACKAGE = "..mapper..";
public static final String REPOSITORY_PACKAGE = "..repositories..";
public static final String SERVICE_PACKAGE = "..services..";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ControllerRulesTest {
+ ", and not with @Controller");

@ArchTest
static final ArchRule classes_should_not_be_public = classes()
static final ArchRule classes_should_be_package_private = classes()
.that()
.resideInAPackage(CONTROLLER_PACKAGE)
.should()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.example.archunit.architecture;

import static com.example.archunit.architecture.ArchitectureConstants.DEFAULT_PACKAGE;
import static com.example.archunit.architecture.ArchitectureConstants.ENTITY_PACKAGE;
import static com.example.archunit.architecture.CommonRules.publicAndFinalFieldsAreNotAllowedRule;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.fields;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods;
import static com.tngtech.archunit.library.GeneralCodingRules.DEPRECATED_API_SHOULD_NOT_BE_USED;
import static com.tngtech.archunit.library.GeneralCodingRules.NO_CLASSES_SHOULD_ACCESS_STANDARD_STREAMS;
import static com.tngtech.archunit.library.GeneralCodingRules.NO_CLASSES_SHOULD_THROW_GENERIC_EXCEPTIONS;
import static com.tngtech.archunit.library.GeneralCodingRules.NO_CLASSES_SHOULD_USE_FIELD_INJECTION;
import static com.tngtech.archunit.library.GeneralCodingRules.NO_CLASSES_SHOULD_USE_JAVA_UTIL_LOGGING;
import static com.tngtech.archunit.library.GeneralCodingRules.NO_CLASSES_SHOULD_USE_JODATIME;

Expand Down Expand Up @@ -35,6 +39,12 @@ class GeneralCodingRulesTest {
static final ArchRule noJavaUtilLogging =
NO_CLASSES_SHOULD_USE_JAVA_UTIL_LOGGING.because("Use org.slf4j.Logger instead");

@ArchTest
static final ArchRule noFieldInjection = NO_CLASSES_SHOULD_USE_FIELD_INJECTION;

@ArchTest
static final ArchRule deprecatedApiShouldNotBeUsed = DEPRECATED_API_SHOULD_NOT_BE_USED;

// Fields
@ArchTest
static final ArchRule loggersShouldBePrivateStaticAndFinal = fields().that()
Expand Down Expand Up @@ -70,4 +80,8 @@ class GeneralCodingRulesTest {
.should()
.bePackagePrivate()
.because("@Bean annotation should not be declared as public methods");

@ArchTest
static final ArchRule public_and_final_fields_are_not_allowed =
publicAndFinalFieldsAreNotAllowedRule(ENTITY_PACKAGE);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public class ContainersConfig {
@Bean
@ServiceConnection
PostgreSQLContainer<?> postgreSQLContainer() {
return new PostgreSQLContainer<>(DockerImageName.parse("postgres:16.3-alpine"));
return new PostgreSQLContainer<>(DockerImageName.parse("postgres").withTag("16.3-alpine"));
}
}

0 comments on commit 9022c64

Please sign in to comment.