Skip to content

Latest commit

 

History

History

jmolecules-archunit

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

jMolecules ArchUnit rules

This module contains ArchUnit rules to verify the integrity of domain concepts expressed via jMolecules DDD annotations or types.

To use these rules, declare the following artifact as dependencies of your project:

Maven dependency
<dependency>
  <groupId>org.jmolecules.integrations</groupId>
  <artifactId>jmolecules-archunit</artifactId>
  <version>${jmolecules-integrations.version}</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>com.tngtech.archunit</groupId>
  <artifactId>archunit-junit5</artifactId>
  <version>${archunit.version}</version>
  <scope>test</scope>
</dependency>

The provided rules can then be used in a JUnit test as follows:

import static org.assertj.core.api.Assertions.*;

import com.tngtech.archunit.core.domain.*;
import com.tngtech.archunit.junit.*;
import com.tngtech.archunit.lang.*;

import org.jmolecules.archunit.*;

@AnalyzeClasses(packages = "example") // (1)
class JMoleculesRulesUnitTest {

  @ArchTest ArchRule dddRules = JMoleculesDddRules.all(); // (2)
  @ArchTest ArchRule onion = JMoleculesArchitectureRules.ensureOnionSimple(); // (2)

  // alternatively

  @ArchTest // (3)
  void detectsViolations(JavaClasses classes) {

    EvaluationResult result = JMoleculesDddRules.all().evaluate(classes);

    assertThat(result.hasViolation()).isFalse();
  }
}
  1. The @AnalyzeClasses(…) annotation defines the scope of the classes to be verified. This is likely to be the base package of your application.

  2. The property style architecture definition can be used simply declaring the rule as a field annotated with @ArchTest. ArchUnit will verify the classes pointed to by <1> and the test will fail if violations occur.

  3. If you prefer to manually evaluate the violations, you can also declare a method annotated with @ArchTest and get the classes scanned for handed in as method argument.

For detailed information about the rules, be sure to check out the types and method definitions in org.jmolecules.archunit.