public class Assertive extends Object
Violations indicate the presence of a programming error. Never try to catch and recover from a programming error. Rather a reasonable global approach would be to return a HTTP 500 response, restart the application or similar.
Make use of hamcrest matchers to conveniently express conditions and get clear error messages. Example:
require(i, greaterThan(0));
All error messages are format strings
as defined by String
.
require(i > 0, "The value must be greater than zero: %d", i);
Modifier and Type | Field and Description |
---|---|
static String |
ASSERTIVE_PROPERTY_NAME |
static String |
DEFAULT_PROVIDER |
static String |
DISABLED |
static String |
DISABLED_PROVIDER |
Modifier and Type | Method and Description |
---|---|
static void |
ensure(boolean condition)
Postcondition that supplier are supposed to ensure.
|
static void |
ensure(boolean condition,
String msg,
Object... values)
Postcondition that supplier are supposed to ensure.
|
static <T> T |
ensure(T o,
org.hamcrest.Matcher<?> matcher)
Postcondition that supplier are supposed to ensure.
|
static void |
neverGetHere()
Unreachable code have been reached.
|
static void |
neverGetHere(String msg)
Unreachable code have been reached.
|
static void |
neverGetHere(String msg,
Object... values)
Unreachable code have been reached.
|
static void |
neverGetHere(Throwable t)
Unexpected exception have been caught.
|
static void |
neverGetHere(Throwable t,
String msg,
Object... values)
Unexpected exception have been caught.
|
static Error |
neverGetHereError()
Unreachable code have been reached.
|
static Error |
neverGetHereError(String msg)
Unreachable code have been reached.
|
static Error |
neverGetHereError(String msg,
Object... values)
Unreachable code have been reached.
|
static Error |
neverGetHereError(Throwable t)
Unexpected exception have been caught.
|
static Error |
neverGetHereError(Throwable t,
String msg,
Object... values)
Unexpected exception have been caught.
|
static void |
require(boolean condition)
Precondition that clients are required to fulfill.
|
static void |
require(boolean condition,
String msg,
Object... values)
Precondition that clients are required to fulfill.
|
static <T> T |
require(T o,
org.hamcrest.Matcher<?> matcher)
Precondition that clients are required to fulfill.
|
public static final String ASSERTIVE_PROPERTY_NAME
public static final String DISABLED
public static final String DEFAULT_PROVIDER
public static final String DISABLED_PROVIDER
public static void require(boolean condition)
condition
- the condition to checkpublic static <T> T require(T o, org.hamcrest.Matcher<?> matcher)
T
- type of object to checko
- the object to checkmatcher
- the matcher that the given object must satisfypublic static void require(boolean condition, String msg, Object... values)
condition
- the condition to checkmsg
- message format string
values
- values passed into the msg format stringpublic static void ensure(boolean condition)
condition
- the condition to checkpublic static <T> T ensure(T o, org.hamcrest.Matcher<?> matcher)
T
- type of object to checko
- the object to checkmatcher
- the matcher that the given object must satisfypublic static void ensure(boolean condition, String msg, Object... values)
condition
- the condition to checkmsg
- message format string
values
- values passed into the msg format stringpublic static void neverGetHere()
public static void neverGetHere(String msg)
msg
- descriptive messagepublic static void neverGetHere(String msg, Object... values)
msg
- message format string
values
- values passed into the msg format stringpublic static void neverGetHere(Throwable t)
t
- the throwable being unexpectedly caught.public static void neverGetHere(Throwable t, String msg, Object... values)
t
- the throwable being unexpectedly caught.msg
- message format string
values
- values passed into the msg format stringpublic static Error neverGetHereError()
public static Error neverGetHereError(String msg)
msg
- descriptive messagepublic static Error neverGetHereError(String msg, Object... values)
msg
- message format string
values
- values passed into the msg format stringpublic static Error neverGetHereError(Throwable t)
t
- the throwable being unexpectedly caught.public static Error neverGetHereError(Throwable t, String msg, Object... values)
t
- the throwable being unexpectedly caught.msg
- message format string
values
- values passed into the msg format stringCopyright © 2014–2015 valid4j. All rights reserved.