public final class AssertionVerifier extends Object implements Verifier
Unlike Requirements, instances of this class can be configured prior to initiating
verification. Doing so causes the same configuration to get reused across runs.
| Constructor and Description |
|---|
AssertionVerifier(boolean enabled)
Creates a new assertion verifier.
|
| Modifier and Type | Method and Description |
|---|---|
AssertionVerifier |
addContext(String key,
Object value)
Appends contextual information to the exception message.
|
boolean |
isEnabled() |
BigDecimalRequirements |
requireThat(BigDecimal parameter,
String name)
Same as
RequirementVerifier.requireThat(BigDecimal, String) but does nothing if
assertions are disabled. |
<T> ClassRequirements<T> |
requireThat(Class<T> parameter,
String name)
Same as
RequirementVerifier.requireThat(Class, String) but does nothing if assertions
are disabled. |
<E> CollectionRequirements<E> |
requireThat(Collection<E> parameter,
String name)
Same as
RequirementVerifier.requireThat(Collection, String) but does nothing if
assertions are disabled. |
DoubleRequirements |
requireThat(Double parameter,
String name)
Verifies requirements of a
Double. |
<K,V> MapRequirements<K,V> |
requireThat(Map<K,V> parameter,
String name)
Same as
RequirementVerifier.requireThat(Map, String) but does nothing if assertions are
disabled. |
ObjectRequirements<Object> |
requireThat(Object parameter,
String name)
Same as
RequirementVerifier.requireThat(Object, String) but does nothing if assertions
are disabled. |
OptionalRequirements |
requireThat(Optional<?> parameter,
String name)
Same as
RequirementVerifier.requireThat(Optional, String) but does nothing if
assertions are disabled. |
PathRequirements |
requireThat(Path parameter,
String name)
Same as
RequirementVerifier.requireThat(Path, String) but does nothing if assertions
are disabled. |
StringRequirements |
requireThat(String parameter,
String name)
Same as
RequirementVerifier.requireThat(String, String) but does nothing if assertions
are disabled. |
<T extends Comparable<? super T>> |
requireThat(T parameter,
String name)
Same as
RequirementVerifier.requireThat(Comparable, String) but does nothing if
assertions are disabled. |
<T extends Number & Comparable<? super T>> |
requireThat(T parameter,
String name)
Same as
RequirementVerifier.requireThat(Number, String) but does nothing if assertions
are disabled. |
UriRequirements |
requireThat(URI parameter,
String name)
Same as
RequirementVerifier.requireThat(URI, String) but does nothing if assertions are
disabled. |
AssertionVerifier |
withContext(List<Map.Entry<String,Object>> context)
Sets the contextual information to append to the exception message.
|
AssertionVerifier |
withException(Class<? extends RuntimeException> exception)
Overrides the type of exception that will get thrown if a requirement fails.
|
public AssertionVerifier(boolean enabled)
To look up whether assertions are enabled for a particular class, invoke:
boolean assertionsEnabled = false;
assert (assertionsEnabled = true);
from within the class in question.
enabled - true if assertions are enabled for the class whose requirements are being
verifiedpublic boolean isEnabled()
public AssertionVerifier withException(Class<? extends RuntimeException> exception)
VerifierThe exception class must define the following constructors:
<init>(String message)
<init>(String message, Throwable cause)
withException in interface Verifierexception - the type of exception to throw, null to throw the default exception
type@Beta public AssertionVerifier addContext(String key, Object value) throws NullPointerException
VerifieraddContext in interface Verifierkey - a keyvalue - a valueNullPointerException - if key is null@Beta public AssertionVerifier withContext(List<Map.Entry<String,Object>> context) throws NullPointerException
VerifierwithContext in interface Verifiercontext - the contextual informationNullPointerException - if context is nullpublic ObjectRequirements<Object> requireThat(Object parameter, String name) throws NullPointerException, IllegalArgumentException
RequirementVerifier.requireThat(Object, String) but does nothing if assertions
are disabled.
parameter - the value of the parametername - the name of the parameterNullPointerException - if name is nullIllegalArgumentException - if name is emptypublic <E> CollectionRequirements<E> requireThat(Collection<E> parameter, String name) throws NullPointerException, IllegalArgumentException
RequirementVerifier.requireThat(Collection, String) but does nothing if
assertions are disabled.
E - the type of element in the collectionparameter - the value of the parametername - the name of the parameterNullPointerException - if name is nullIllegalArgumentException - if name is emptypublic <T extends Comparable<? super T>> ComparableRequirements<T> requireThat(T parameter, String name) throws NullPointerException, IllegalArgumentException
RequirementVerifier.requireThat(Comparable, String) but does nothing if
assertions are disabled.
T - the type of the numberparameter - the value of the parametername - the name of the parameterNullPointerException - if name is nullIllegalArgumentException - if name is emptypublic <T extends Number & Comparable<? super T>> NumberRequirements<T> requireThat(T parameter, String name) throws NullPointerException, IllegalArgumentException
RequirementVerifier.requireThat(Number, String) but does nothing if assertions
are disabled.T - the type of the numberparameter - the value of the parametername - the name of the parameterNullPointerException - if name is nullIllegalArgumentException - if name is emptypublic DoubleRequirements requireThat(Double parameter, String name) throws NullPointerException, IllegalArgumentException
Double.parameter - the value of the parametername - the name of the parameterNullPointerException - if name is nullIllegalArgumentException - if name is emptypublic BigDecimalRequirements requireThat(BigDecimal parameter, String name) throws NullPointerException, IllegalArgumentException
RequirementVerifier.requireThat(BigDecimal, String) but does nothing if
assertions are disabled.
parameter - the value of the parametername - the name of the parameterNullPointerException - if name is nullIllegalArgumentException - if name is emptypublic <K,V> MapRequirements<K,V> requireThat(Map<K,V> parameter, String name) throws NullPointerException, IllegalArgumentException
RequirementVerifier.requireThat(Map, String) but does nothing if assertions are
disabled.
K - the type of key in the mapV - the type of value in the mapparameter - the value of the parametername - the name of the parameterNullPointerException - if name is nullIllegalArgumentException - if name is emptypublic PathRequirements requireThat(Path parameter, String name) throws NullPointerException, IllegalArgumentException
RequirementVerifier.requireThat(Path, String) but does nothing if assertions
are disabled.
parameter - the value of the parametername - the name of the parameterNullPointerException - if name is nullIllegalArgumentException - if name is emptypublic StringRequirements requireThat(String parameter, String name) throws NullPointerException, IllegalArgumentException
RequirementVerifier.requireThat(String, String) but does nothing if assertions
are disabled.
parameter - the value of the parametername - the name of the parameterNullPointerException - if name is nullIllegalArgumentException - if name is emptypublic UriRequirements requireThat(URI parameter, String name) throws NullPointerException, IllegalArgumentException
RequirementVerifier.requireThat(URI, String) but does nothing if assertions are
disabled.
parameter - the value of the parametername - the name of the parameterNullPointerException - if name is nullIllegalArgumentException - if name is emptypublic <T> ClassRequirements<T> requireThat(Class<T> parameter, String name) throws NullPointerException, IllegalArgumentException
RequirementVerifier.requireThat(Class, String) but does nothing if assertions
are disabled.
T - the type of classparameter - the value of the parametername - the name of the parameterNullPointerException - if name is nullIllegalArgumentException - if name is emptypublic OptionalRequirements requireThat(Optional<?> parameter, String name) throws NullPointerException, IllegalArgumentException
RequirementVerifier.requireThat(Optional, String) but does nothing if
assertions are disabled.
parameter - the value of the parametername - the name of the parameterNullPointerException - if name is nullIllegalArgumentException - if name is emptyCopyright © 2016. All rights reserved.