public final class Ensure
extends java.lang.Object
Assert because JUnit etc.
If in doubt, use that(boolean, String).| Modifier and Type | Method and Description |
|---|---|
static <T extends java.lang.Throwable> |
checked(boolean predicate,
java.lang.String explanation,
java.util.function.Function<java.lang.String,T> exceptionFactory)
Usage:
Ensure.checked(connection != null, "connection != null", IOException::new);
The throwable type must have a constructor checked just takes a String. |
static void |
that(boolean predicate,
java.lang.String explanation)
Throws an
AssertionError if predicate is false. |
static <T extends java.lang.Throwable> |
unchecked(boolean predicate,
java.lang.String explanation,
java.util.function.Function<java.lang.String,T> exceptionFactory)
As
checked(boolean, String, Function) except the throwable is thrown as an unchecked exception type. |
public static <T extends java.lang.Throwable> void checked(boolean predicate,
java.lang.String explanation,
java.util.function.Function<java.lang.String,T> exceptionFactory)
throws T extends java.lang.Throwable
Ensure.checked(connection != null, "connection != null", IOException::new);
The throwable type must have a constructor checked just takes a String.T - the type to throwpredicate - the conditionexplanation - failure reasonexceptionFactory - source of errorT - if predicate is falseT extends java.lang.Throwablepublic static void that(boolean predicate,
java.lang.String explanation)
AssertionError if predicate is false.
Usage: Ensure.that(foo != null, "foo != null");predicate - the conditionexplanation - failure reasonpublic static <T extends java.lang.Throwable> void unchecked(boolean predicate,
java.lang.String explanation,
java.util.function.Function<java.lang.String,T> exceptionFactory)
checked(boolean, String, Function) except the throwable is thrown as an unchecked exception type.T - the type to throwpredicate - the conditionexplanation - failure reasonexceptionFactory - source of errorExceptions.throwChecked(Throwable)