Package com.tngtech.archunit.lang
Class ArchCondition<T>
java.lang.Object
com.tngtech.archunit.lang.ArchCondition<T>
- Direct Known Subclasses:
AllDependenciesCondition
,AnyDependencyCondition
,ArchCondition.ConditionByPredicate
,PlantUmlArchCondition
,TransitiveDependencyCondition
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
AnArchCondition
that derives which objects satisfy/violate the condition from aDescribedPredicate
. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionand
(ArchCondition<? super T> condition) Overwrites the description of thisArchCondition
.abstract void
check
(T item, ConditionEvents events) void
finish
(ConditionEvents events) Can be used/overridden to finish the evaluation of this condition.
ArchUnit will call this method once after every single item was checked (bycheck(Object, ConditionEvents)
).
This method can be used, if violations are dependent on multiple/allcheck(Object, ConditionEvents)
calls, on the contrary to the default case, where each singlecheck(Object, ConditionEvents)
stands for itself.<U extends T>
ArchCondition<U>Convenience method to downcast the condition.static <T extends HasDescription & HasSourceCodeLocation>
ArchCondition.ConditionByPredicate<T>from
(DescribedPredicate<? super T> predicate) Creates anArchCondition
from aDescribedPredicate
.void
init
(Collection<T> allObjectsToTest) Can be used/overridden to prepare this condition with respect to the collection of all objects the condition will be tested against.
ArchUnit will call this method once in the beginning, before starting to check single items.or
(ArchCondition<? super T> condition) toString()
-
Constructor Details
-
ArchCondition
-
-
Method Details
-
init
Can be used/overridden to prepare this condition with respect to the collection of all objects the condition will be tested against.
ArchUnit will call this method once in the beginning, before starting to check single items.- Parameters:
allObjectsToTest
- All objects thatcheck(Object, ConditionEvents)
will be called against
-
check
-
finish
Can be used/overridden to finish the evaluation of this condition.
ArchUnit will call this method once after every single item was checked (bycheck(Object, ConditionEvents)
).
This method can be used, if violations are dependent on multiple/allcheck(Object, ConditionEvents)
calls, on the contrary to the default case, where each singlecheck(Object, ConditionEvents)
stands for itself. -
and
-
or
-
getDescription
-
as
Overwrites the description of thisArchCondition
. E.g.
would then yieldclasses().should(condition.as("some customized description with '%s'", "parameter"))
classes should some customized description with 'parameter'
.- Parameters:
description
- The new description of thisArchCondition
args
- Optional arguments to fill into the description viaString.format(String, Object...)
- Returns:
- An
ArchCondition
with adjusteddescription
.
-
toString
-
forSubtype
Convenience method to downcast the condition.ArchConditions
are contravariant by nature, i.e. anArchCondition<T>
is an instance ofArchCondition<V>
, if and only ifV
is an instance ofT
.
Take for exampleObject > String
. Obviously anArchCondition<Object>
is also anArchCondition<String>
.
Unfortunately, the Java type system does not allow us to express this property of the type parameter ofArchCondition
. So to avoid forcing users to cast everywhere it is possible to use this method which also documents the intention and reasoning.- Type Parameters:
U
- A subtype of theArchCondition's
type parameterT
- Returns:
- An
ArchCondition
accepting a subtype of the condition's actual type parameterT
-
from
@PublicAPI(usage=ACCESS) public static <T extends HasDescription & HasSourceCodeLocation> ArchCondition.ConditionByPredicate<T> from(DescribedPredicate<? super T> predicate) Creates anArchCondition
from aDescribedPredicate
. For more information seeConditionByPredicate
. For more convenient versions of this method compareArchConditions.have(DescribedPredicate)
andArchConditions.be(DescribedPredicate)
.- Type Parameters:
T
- The type of object thecondition
will check- Parameters:
predicate
- Specifies which objects satisfy the condition.- Returns:
- A
ConditionByPredicate
derived from the suppliedpredicate
- See Also:
-