Package com.tngtech.archunit.library
Class Architectures.LayeredArchitecture
java.lang.Object
com.tngtech.archunit.library.Architectures.LayeredArchitecture
- All Implemented Interfaces:
HasDescription,CanOverrideDescription<ArchRule>,ArchRule,CanBeEvaluated
- Enclosing class:
- Architectures
@PublicAPI(usage=ACCESS)
public static final class Architectures.LayeredArchitecture
extends Object
implements ArchRule
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classDefines which dependencies the layered architecture will consider when checking for violations.final classfinal classNested classes/interfaces inherited from interface com.tngtech.archunit.lang.ArchRule
ArchRule.Assertions, ArchRule.Factory, ArchRule.Transformation -
Method Summary
Modifier and TypeMethodDescriptionallowEmptyShould(boolean allowEmptyShould) This method is equivalent to callingwithOptionalLayers(boolean), which should be preferred in this context as the meaning is easier to understand.Allows to adjust the description of this object.voidcheck(JavaClasses classes) Ensure that all classes under test are contained within a defined layer of the architecture.ensureAllClassesAreContainedInArchitectureIgnoring(DescribedPredicate<? super JavaClass> predicate) LikeensureAllClassesAreContainedInArchitecture()but will ignore classes in packages matching the specifiedpredicate.ensureAllClassesAreContainedInArchitectureIgnoring(String... packageIdentifiers) LikeensureAllClassesAreContainedInArchitecture()but will ignore classes in packages matching the specifiedpackageIdentifiers.evaluate(JavaClasses classes) ignoreDependency(DescribedPredicate<? super JavaClass> origin, DescribedPredicate<? super JavaClass> target) Same asignoreDependency(Class, Class)but allows specifying origin and target by freely defined predicates.ignoreDependency(Class<?> origin, Class<?> target) Configures the rule to ignore any violation from a specificoriginclass to a specifictargetclass.ignoreDependency(String originFullyQualifiedClassName, String targetFullyQualifiedClassName) Same asignoreDependency(Class, Class)but allows specifying origin and target as fully qualified class names.Starts the definition of a new layer within the currentLayeredArchitecture.optionalLayer(String name) Starts the definition of a new optional layer within the currentLayeredArchitecture.toString()whereLayer(String name) Allows restricting accesses to or from this layer.withOptionalLayers(boolean optionalLayers) By default, layers defined withlayer(String)must not be empty, i.e.
-
Method Details
-
withOptionalLayers
@PublicAPI(usage=ACCESS) public Architectures.LayeredArchitecture withOptionalLayers(boolean optionalLayers) By default, layers defined withlayer(String)must not be empty, i.e. contain at least one class.
withOptionalLayers(true)can be used to make all layers optional.
withOptionalLayers(false)still allows to define individual optional layers withoptionalLayer(String).- See Also:
-
layer
@PublicAPI(usage=ACCESS) public Architectures.LayeredArchitecture.LayerDefinition layer(String name) Starts the definition of a new layer within the currentLayeredArchitecture.
UnlesswithOptionalLayers(true} is used, this layer must not be empty.- See Also:
-
optionalLayer
@PublicAPI(usage=ACCESS) public Architectures.LayeredArchitecture.LayerDefinition optionalLayer(String name) Starts the definition of a new optional layer within the currentLayeredArchitecture.
An optional layer will not fail if it is empty, i.e. does not contain any classes. WhenwithOptionalLayers(true)is used, all layers are optional by default, such that there is no difference betweenoptionalLayer(String)andlayer(String)anymore -
getDescription
- Specified by:
getDescriptionin interfaceHasDescription
-
toString
-
evaluate
- Specified by:
evaluatein interfaceCanBeEvaluated
-
ensureAllClassesAreContainedInArchitecture
@PublicAPI(usage=ACCESS) public Architectures.LayeredArchitecture ensureAllClassesAreContainedInArchitecture()Ensure that all classes under test are contained within a defined layer of the architecture. -
ensureAllClassesAreContainedInArchitectureIgnoring
@PublicAPI(usage=ACCESS) public Architectures.LayeredArchitecture ensureAllClassesAreContainedInArchitectureIgnoring(String... packageIdentifiers) LikeensureAllClassesAreContainedInArchitecture()but will ignore classes in packages matching the specifiedpackageIdentifiers.- Parameters:
packageIdentifiers-packageIdentifiersspecifying which classes may live outside the architecture- See Also:
-
ensureAllClassesAreContainedInArchitectureIgnoring
@PublicAPI(usage=ACCESS) public Architectures.LayeredArchitecture ensureAllClassesAreContainedInArchitectureIgnoring(DescribedPredicate<? super JavaClass> predicate) LikeensureAllClassesAreContainedInArchitecture()but will ignore classes in packages matching the specifiedpredicate.
Note that many predefinedpredicatescan be found within a subclassPredicatesof the respective domain object or a common ancestor. For example,predicatestargetingJavaClasscan be found withinJavaClass.Predicatesor one of the respective ancestors likeHasName.Predicates.- Parameters:
predicate-predicatespecifying which classes may live outside the architecture- See Also:
-
check
-
because
-
allowEmptyShould
This method is equivalent to callingwithOptionalLayers(boolean), which should be preferred in this context as the meaning is easier to understand.- Specified by:
allowEmptyShouldin interfaceArchRule- Parameters:
allowEmptyShould- Whether the rule fails if the should-clause is evaluated with an empty set of elements- Returns:
- A (new)
ArchRulewith adjustedallowEmptyShouldbehavior
-
as
Description copied from interface:CanOverrideDescriptionAllows to adjust the description of this object. Note that this method will not modify the current object, but instead return a new object with adjusted description.- Specified by:
asin interfaceCanOverrideDescription<ArchRule>- Parameters:
newDescription- The description the result of this method will hold- Returns:
- A new equivalent object with adjusted description
-
ignoreDependency
@PublicAPI(usage=ACCESS) public Architectures.LayeredArchitecture ignoreDependency(Class<?> origin, Class<?> target) Configures the rule to ignore any violation from a specificoriginclass to a specifictargetclass.- Parameters:
origin- AClassobject specifying the origin of aDependencyto ignoretarget- AClassobject specifying the target of aDependencyto ignore- Returns:
- a
Architectures.LayeredArchitectureto be used as anArchRuleor further restricted through a fluent API.
-
ignoreDependency
@PublicAPI(usage=ACCESS) public Architectures.LayeredArchitecture ignoreDependency(String originFullyQualifiedClassName, String targetFullyQualifiedClassName) Same asignoreDependency(Class, Class)but allows specifying origin and target as fully qualified class names. -
ignoreDependency
@PublicAPI(usage=ACCESS) public Architectures.LayeredArchitecture ignoreDependency(DescribedPredicate<? super JavaClass> origin, DescribedPredicate<? super JavaClass> target) Same asignoreDependency(Class, Class)but allows specifying origin and target by freely defined predicates. Any dependency where theDependency.getOriginClass()matches theoriginpredicate and theDependency.getTargetClass()matches thetargetpredicate will be ignored. -
whereLayer
@PublicAPI(usage=ACCESS) public Architectures.LayeredArchitecture.LayerDependencySpecification whereLayer(String name) Allows restricting accesses to or from this layer. Note that "access" in the context of a layer refers to any dependency as defined byDependency.- Parameters:
name- a layer name as specified before vialayer(String)- Returns:
- a specification to fluently define further restrictions
-