Package com.tngtech.archunit.lang
Class ArchCondition.ConditionByPredicate<T extends HasDescription & HasSourceCodeLocation>
java.lang.Object
com.tngtech.archunit.lang.ArchCondition<T>
com.tngtech.archunit.lang.ArchCondition.ConditionByPredicate<T>
- Type Parameters:
T
- The type of object the condition will test
- Enclosing class:
- ArchCondition<T>
@PublicAPI(usage=ACCESS)
public static final class ArchCondition.ConditionByPredicate<T extends HasDescription & HasSourceCodeLocation>
extends ArchCondition<T>
An
ArchCondition
that derives which objects satisfy/violate the condition from a DescribedPredicate
.
The description is taken from the defining predicate
but can be overridden via as(String, Object...)
.
How the message of each single event
is derived can be customized by describeEventsBy(EventDescriber)
.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Defines how to describe a singleConditionEvent
.Nested classes/interfaces inherited from class com.tngtech.archunit.lang.ArchCondition
ArchCondition.ConditionByPredicate<T extends HasDescription & HasSourceCodeLocation>
-
Method Summary
Modifier and TypeMethodDescriptionOverwrites the description of thisArchCondition
.void
check
(T object, ConditionEvents events) describeEventsBy
(ArchCondition.ConditionByPredicate.EventDescriber eventDescriber) <U extends T>
ArchCondition.ConditionByPredicate<U>Convenience method to downcast the condition.Methods inherited from class com.tngtech.archunit.lang.ArchCondition
and, finish, from, getDescription, init, or, toString
-
Method Details
-
describeEventsBy
@PublicAPI(usage=ACCESS) public ArchCondition.ConditionByPredicate<T> describeEventsBy(ArchCondition.ConditionByPredicate.EventDescriber eventDescriber) Adjusts how thiscondition
will create the description of theevents
. E.g. assume thepredicate
of this condition issimpleName(name)
, then this method could be used to adjust the event description ascondition.describeEventsBy((predicateDescription, satisfied) -> (satisfied ? "has " : "does not have ") + predicateDescription )
- Parameters:
eventDescriber
- Specifies how to create the description of theConditionEvent
whenever the predicate is evaluated against an object.- Returns:
- A
ConditionByPredicate
that describes itsevents
with the givenEventDescriber
-
as
Description copied from class:ArchCondition
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'
.- Overrides:
as
in classArchCondition<T extends HasDescription & HasSourceCodeLocation>
- Parameters:
description
- The new description of thisArchCondition
args
- Optional arguments to fill into the description viaString.format(String, Object...)
- Returns:
- An
ArchCondition
with adjusteddescription
.
-
forSubtype
Description copied from class:ArchCondition
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.- Overrides:
forSubtype
in classArchCondition<T extends HasDescription & HasSourceCodeLocation>
- Type Parameters:
U
- A subtype of theArchCondition's
type parameterT
- Returns:
- An
ArchCondition
accepting a subtype of the condition's actual type parameterT
-
check
- Specified by:
check
in classArchCondition<T extends HasDescription & HasSourceCodeLocation>
-