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
Modifier and TypeClassDescriptionstatic final class
Defines which dependencies the layered architecture will consider when checking for violations.final class
final class
Nested 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.void
check
(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 specificorigin
class to a specifictarget
class.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:
getDescription
in interfaceHasDescription
-
toString
-
evaluate
- Specified by:
evaluate
in 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
-packageIdentifiers
specifying 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 predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaClass
can be found withinJavaClass.Predicates
or one of the respective ancestors likeHasName.Predicates
.- Parameters:
predicate
-predicate
specifying 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:
allowEmptyShould
in interfaceArchRule
- Parameters:
allowEmptyShould
- Whether the rule fails if the should-clause is evaluated with an empty set of elements- Returns:
- A (new)
ArchRule
with adjustedallowEmptyShould
behavior
-
as
Description copied from interface:CanOverrideDescription
Allows 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:
as
in 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 specificorigin
class to a specifictarget
class.- Parameters:
origin
- AClass
object specifying the origin of aDependency
to ignoretarget
- AClass
object specifying the target of aDependency
to ignore- Returns:
- a
Architectures.LayeredArchitecture
to be used as anArchRule
or 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 theorigin
predicate and theDependency.getTargetClass()
matches thetarget
predicate 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
-