Skip to content

Instantly share code, notes, and snippets.

@andres-sacco
Created January 16, 2021 00:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andres-sacco/774bf7e86477484a7429607c2c87880b to your computer and use it in GitHub Desktop.
Save andres-sacco/774bf7e86477484a7429607c2c87880b to your computer and use it in GitHub Desktop.
Service rules
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule;
import com.tngtech.archunit.core.importer.ImportOption;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.fields;
@AnalyzeClasses(packages = "com.example.archunit", importOptions = ImportOption.DoNotIncludeTests.class) //1
class ServiceRulesTest {
@ArchTest //2
static final ArchRule fields_should_not_be_public = fields()
.that().areDeclaredInClassesThat()
.resideInAPackage("com.example.archunit.service")
.should().notBePublic()
.because("Public fields are not allowed in Service classes"); //3
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment