Skip to content

Instantly share code, notes, and snippets.

@BenjaminKlatt
Created October 12, 2020 15:39
Show Gist options
  • Save BenjaminKlatt/9c485a54b006545cb1fdd30400838dd7 to your computer and use it in GitHub Desktop.
Save BenjaminKlatt/9c485a54b006545cb1fdd30400838dd7 to your computer and use it in GitHub Desktop.
ArchUnit Basis Test
package de.viadee.architecture.archunit.architecture;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
import org.junit.jupiter.api.Test;
import com.tngtech.archunit.core.domain.JavaClasses;
import com.tngtech.archunit.core.importer.ClassFileImporter;
import com.tngtech.archunit.lang.ArchRule;
public class SimpleArchitectureTest {
@Test
public void controllers_should_not_access_persistence() {
JavaClasses importedClasses =
new ClassFileImporter().importPackages("de.viadee.architecture.archunit");
ArchRule rule = noClasses().that().resideInAPackage("..controller..").should()
.dependOnClassesThat().resideInAPackage("..persistence..")
.because("controllers must use business services instead of the persistence layer");
rule.check(importedClasses);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment