@Immutable
public final class Require
extends Object
Provides assertion services. Replaces the use of the 'assert' instruction which depends on a compile time switch (-ea). Also replaces the use of the AssertJ library which is expected to be run in a test environment. Also replaces the generic use of IllegalStateException with FailureException which subclasses AssertionError instead of RuntimeException.
This class does not use reflection.
Modifier and Type | Class and Description |
---|---|
static class |
Require.FailureException
Failure exception.
|
Modifier and Type | Method and Description |
---|---|
static <T> void |
content(Iterable<T> iterable,
String explanation,
T... content)
Requires a specific content for an iterable.
|
static <T> void |
content(Iterable<T> iterable,
T... content)
Requires a specific content for an iterable.
|
static void |
equal(boolean reference,
boolean value)
Requires boolean equal.
|
static void |
equal(boolean reference,
boolean value,
Object explanation)
Requires boolean equal.
|
static void |
equal(double reference,
double value)
Requires double equal.
|
static void |
equal(double reference,
double value,
double sample)
Requires double equal.
|
static void |
equal(double reference,
double value,
double sample,
Object explanation)
Requires double equal.
|
static void |
equal(double reference,
double value,
Object explanation)
Requires double equal.
|
static void |
equal(long reference,
long value)
Requires long equal.
|
static void |
equal(long reference,
long value,
Object explanation)
Requires long equal.
|
static void |
equal(Object reference,
Object value)
Requires object equal.
|
static void |
equal(Object reference,
Object value,
Object explanation)
Requires object equal.
|
static Require.FailureException |
failure()
Forces a failure.
|
static void |
failure(boolean value)
Failure.
|
static void |
failure(boolean value,
Object explanation)
Failure.
|
static Require.FailureException |
failure(Exception cause)
Failure.
|
static Require.FailureException |
failure(Exception cause,
Object explanation)
Failure.
|
static Require.FailureException |
failure(Object explanation)
Failure.
|
static void |
ignored(boolean value)
Ignores a boolean value.
|
static void |
ignored(double value)
Ignores a double value.
|
static void |
ignored(long value)
Ignores a long value.
|
static void |
ignored(Object value)
Ignores an object value.
|
static String |
notEmpty(String string)
Requires a not empty string.
|
static String |
notEmptyTrimmed(String string)
Requires a not empty trimmed string.
|
static <T> T |
notNull(T object)
Requires an object.
|
static <T> T |
notNull(T object,
Object explanation)
Requires an object.
|
static <T> void |
notPresent(Optional<T> object)
Requires an optional object to not be present.
|
static <T> void |
notPresent(Optional<T> object,
Object explanation)
Requires an optional object to not be present.
|
static <T> void |
present(Optional<T> object)
Requires an optional object to be present.
|
static <T> void |
present(Optional<T> object,
Object explanation)
Requires an optional object to be present.
|
static void |
same(Object reference,
Object value)
Requires the two arguments to be the same object.
|
static void |
same(Object reference,
Object value,
Object explanation)
Requires the two arguments to be the same object.
|
static boolean |
success(boolean value)
Requires success.
|
static boolean |
success(boolean value,
Object explanation)
Requires success.
|
static void |
success(Exception exception)
Requires success.
|
static void |
success(Exception exception,
Object explanation)
Requires success.
|
@SafeVarargs public static <T> void content(@Nonnull Iterable<T> iterable, @Nonnull T... content)
T
- The type of the content objects.iterable
- The iterable.content
- The expected content.@SafeVarargs public static <T> void content(@Nonnull Iterable<T> iterable, @Nonnull String explanation, @Nonnull T... content)
T
- The type of the content objects.iterable
- The iterable.explanation
- Explanatory text.content
- The expected content.public static void equal(boolean reference, boolean value)
reference
- The boolean reference.value
- The boolean value.public static void equal(double reference, double value)
reference
- The double reference.value
- The double value.public static void equal(long reference, long value)
reference
- The long reference.value
- The long value.public static void equal(@Nullable Object reference, @Nullable Object value)
reference
- The reference object.value
- The value object.public static void equal(boolean reference, boolean value, @Nonnull Object explanation)
reference
- The boolean reference.value
- The boolean value.explanation
- Explanatory text.public static void equal(double reference, double value, double sample)
reference
- The double reference.value
- The double value.sample
- A sample value.public static void equal(double reference, double value, @Nonnull Object explanation)
reference
- The double reference.value
- The double value.explanation
- Explanatory text.public static void equal(long reference, long value, @Nonnull Object explanation)
reference
- The long reference.value
- The long value.explanation
- Explanatory text.public static void equal(@Nullable Object reference, @Nullable Object value, @Nonnull Object explanation)
reference
- The reference object.value
- The value object.explanation
- Explanatory text.public static void equal(double reference, double value, double sample, @Nonnull Object explanation)
reference
- The double reference.value
- The double value.sample
- A sample value.explanation
- Explanatory text.public static Require.FailureException failure() throws Require.FailureException
Often used in the 'default' clause of a 'switch' instruction.
Require.FailureException
- Without explanatory text.public static void failure(boolean value)
value
- The value which must be false.Require.FailureException
- Without explanatory text.public static Require.FailureException failure(@Nonnull Exception cause) throws Require.FailureException
cause
- The failure cause.Require.FailureException
- Without explanatory text.public static Require.FailureException failure(@Nonnull Object explanation) throws Require.FailureException
explanation
- Explanatory text.Require.FailureException
- With explanatory text.public static void failure(boolean value, @Nonnull Object explanation)
value
- The value which must be false.explanation
- Explanatory text.Require.FailureException
- When the value is true.public static Require.FailureException failure(@Nonnull Exception cause, @Nonnull Object explanation) throws Require.FailureException
cause
- The failure cause.explanation
- Explanatory text.Require.FailureException
- Without explanatory text.public static void ignored(boolean value)
value
- The value to ignore.public static void ignored(double value)
value
- The value to ignore.public static void ignored(long value)
value
- The value to ignore.public static void ignored(Object value)
value
- The value to ignore.@Nonnull public static String notEmpty(@Nullable String string) throws Require.FailureException
string
- The tested string.Require.FailureException
- For null or empty tested string.@Nonnull @CheckReturnValue public static String notEmptyTrimmed(@Nullable String string) throws Require.FailureException
string
- The tested string.Require.FailureException
- For null or empty tested string.@Nonnull public static <T> T notNull(@Nullable T object) throws Require.FailureException
T
- The type of the tested object.object
- The tested object.Require.FailureException
- For null tested object.@Nonnull public static <T> T notNull(@Nullable T object, @Nonnull Object explanation) throws Require.FailureException
T
- The type of the tested object.object
- The tested object.explanation
- Explanatory text.Require.FailureException
- For null tested object.@Nonnull public static <T> void notPresent(@Nonnull Optional<T> object) throws Require.FailureException
T
- The type of the tested object.object
- The tested optional object.Require.FailureException
- For present tested object.@Nonnull public static <T> void notPresent(@Nonnull Optional<T> object, @Nonnull Object explanation) throws Require.FailureException
T
- The type of the tested object.object
- The tested optional object.explanation
- Explanatory text.Require.FailureException
- For present tested object.@Nonnull public static <T> void present(@Nonnull Optional<T> object) throws Require.FailureException
T
- The type of the tested object.object
- The tested optional object.Require.FailureException
- For non present tested object.@Nonnull public static <T> void present(@Nonnull Optional<T> object, @Nonnull Object explanation) throws Require.FailureException
T
- The type of the tested object.object
- The tested optional object.explanation
- Explanatory text.Require.FailureException
- For non present tested object.public static void same(@Nullable Object reference, @Nullable Object value)
reference
- The reference object.value
- The value object.public static void same(@Nullable Object reference, @Nullable Object value, @Nonnull Object explanation)
reference
- The reference object.value
- The value object.explanation
- Explanatory text.public static boolean success(boolean value)
value
- The value which must be true.Require.FailureException
- When the value is false.public static void success(@Nullable Exception exception)
exception
- A possible exception.Require.FailureException
- When the exception is not null.public static boolean success(boolean value, @Nonnull Object explanation)
value
- The value which must be true.explanation
- Explanatory text.Require.FailureException
- When the value is false.public static void success(@Nullable Exception exception, @Nonnull Object explanation)
exception
- A possible exception.explanation
- Explanatory text.Require.FailureException
- When the exception is not null.Copyright © 2003-2019 Serge Brisson. All Rights Reserved.