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
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDefines 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.voidcheck(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 thisconditionwill create the description of theevents. E.g. assume thepredicateof 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 theConditionEventwhenever the predicate is evaluated against an object.- Returns:
- A
ConditionByPredicatethat describes itseventswith the givenEventDescriber
-
as
Description copied from class:ArchConditionOverwrites 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:
asin classArchCondition<T extends HasDescription & HasSourceCodeLocation>- Parameters:
description- The new description of thisArchConditionargs- Optional arguments to fill into the description viaString.format(String, Object...)- Returns:
- An
ArchConditionwith adjusteddescription.
-
forSubtype
Description copied from class:ArchConditionConvenience method to downcast the condition.ArchConditionsare contravariant by nature, i.e. anArchCondition<T>is an instance ofArchCondition<V>, if and only ifVis 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:
forSubtypein classArchCondition<T extends HasDescription & HasSourceCodeLocation>- Type Parameters:
U- A subtype of theArchCondition'stype parameterT- Returns:
- An
ArchConditionaccepting a subtype of the condition's actual type parameterT
-
check
- Specified by:
checkin classArchCondition<T extends HasDescription & HasSourceCodeLocation>
-