|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.springsource.util.common.Assert
public final class Assert
A set of useful assertions based on those provided by the Spring Framework's Assert class.
Concurrent Semantics
This class is thread safe.
org.junit.Assert
Constructor Summary | |
---|---|
private |
Assert()
|
Method Summary | ||
---|---|---|
static void |
hasLength(java.lang.String text,
java.lang.String message,
java.lang.Object... inserts)
Assert that the given String is not empty; that is, it must not be null and not the empty String. |
|
static
|
isAssignable(java.lang.Class<T> superType,
java.lang.Class<U> subType,
java.lang.String message,
java.lang.Object... inserts)
Assert that superType.isAssignableFrom(subType) is true . |
|
static void |
isFalse(boolean expression,
java.lang.String message,
java.lang.Object... inserts)
Assert a boolean expression, throwing a IllegalArgumentException if the test result is
true . |
|
static
|
isInstanceOf(java.lang.Class<T> type,
java.lang.Object obj,
java.lang.String message,
java.lang.Object... inserts)
Assert that the provided object is a non-null instance of the provided class. |
|
static void |
isNull(java.lang.Object object,
java.lang.String message,
java.lang.Object... inserts)
Assert that an object is null . |
|
static void |
isTrue(boolean expression,
java.lang.String message,
java.lang.Object... inserts)
Assert a boolean expression, throwing a IllegalArgumentException if the test result is
false . |
|
static
|
notEmpty(java.util.Collection<T> collection,
java.lang.String message,
java.lang.Object... inserts)
Assert that a collection has elements; that is, it must not be null and must have at least one
element. |
|
static
|
notEmpty(java.util.Map<K,V> map,
java.lang.String message,
java.lang.Object... inserts)
Assert that a Map has entries; that is, it must not be null and must have at least one entry. |
|
static void |
notEmpty(java.lang.Object[] array,
java.lang.String message,
java.lang.Object... inserts)
Assert that an array has elements; that is, it must not be null and must have at least one
element. |
|
static void |
notNull(java.lang.Object object,
java.lang.String message,
java.lang.Object... inserts)
Assert that an object is not null . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
private Assert()
Method Detail |
---|
public static void isTrue(boolean expression, java.lang.String message, java.lang.Object... inserts)
IllegalArgumentException
if the test result is
false
.
Assert.isTrue(i > 0, "The value must be greater than zero");
expression
- a boolean expressionmessage
- the exception message to use if the assertion failsinserts
- any inserts to include if the message is a format string.
java.lang.IllegalArgumentException
- if expression is false
public static void isFalse(boolean expression, java.lang.String message, java.lang.Object... inserts)
IllegalArgumentException
if the test result is
true
.
Assert.isFalse(state.isBroken(), "The state is broken");
expression
- a boolean expressionmessage
- the exception message to use if the assertion failsinserts
- any inserts to include if the message is a format string.
java.lang.IllegalArgumentException
- if expression is false
public static void isNull(java.lang.Object object, java.lang.String message, java.lang.Object... inserts)
null
.
Assert.isNull(value, "The value must be null");
object
- the object to checkmessage
- the exception message to use if the assertion failsinserts
- any inserts to include if the message is a format string.
java.lang.IllegalArgumentException
- if the object is not null
public static void notNull(java.lang.Object object, java.lang.String message, java.lang.Object... inserts)
null
.
Assert.notNull(clazz, "The class must not be null");
object
- the object to checkmessage
- the exception message to use if the assertion failsinserts
- any inserts to include if the message is a format string.
java.lang.IllegalArgumentException
- if the object is null
public static void hasLength(java.lang.String text, java.lang.String message, java.lang.Object... inserts)
null
and not the empty String.
Assert.hasLength(name, "Name must not be empty");
text
- the String to checkmessage
- the exception message to use if the assertion failsinserts
- any inserts to include if the message is a format string.StringUtils.hasLength(java.lang.CharSequence)
public static void notEmpty(java.lang.Object[] array, java.lang.String message, java.lang.Object... inserts)
null
and must have at least one
element.
Assert.notEmpty(array, "The array must have elements");
array
- the array to checkmessage
- the exception message to use if the assertion failsinserts
- any inserts to include if the message is a format string.
java.lang.IllegalArgumentException
- if the object array is null
or has no elementspublic static <T> void notEmpty(java.util.Collection<T> collection, java.lang.String message, java.lang.Object... inserts)
null
and must have at least one
element.
Assert.notEmpty(collection, "Collection must have elements");
T
- the type of the elements of the collectioncollection
- the collection to checkmessage
- the exception message to use if the assertion failsinserts
- any inserts to include if the message is a format string.
java.lang.IllegalArgumentException
- if the collection is null
or has no elementspublic static <K,V> void notEmpty(java.util.Map<K,V> map, java.lang.String message, java.lang.Object... inserts)
null
and must have at least one entry.
Assert.notEmpty(map, "Map must have entries");
K
- type of Key (domain)V
- type of Value (range)map
- the map to checkmessage
- the exception message to use if the assertion failsinserts
- any inserts to include if the message is a format string.
java.lang.IllegalArgumentException
- if the map is null
or has no entriespublic static <T> void isInstanceOf(java.lang.Class<T> type, java.lang.Object obj, java.lang.String message, java.lang.Object... inserts)
Assert.instanceOf(Foo.class, foo);
T
- the type to check this fortype
- the type to check againstobj
- the object to checkmessage
- a message which will be prepended to the message produced by the function itself, and which may be
used to provide context. It should normally end in a ": " or ". " so that the function generate message
looks ok when appended to it.inserts
- any inserts to include if the message is a format string.
java.lang.IllegalArgumentException
- if the object is not an instance of clazzClass.isInstance(java.lang.Object)
public static <T,U> void isAssignable(java.lang.Class<T> superType, java.lang.Class<U> subType, java.lang.String message, java.lang.Object... inserts)
superType.isAssignableFrom(subType)
is true
.
Assert.isAssignable(Number.class, myClass);
T
- the supertypeU
- the subtypesuperType
- the super type to check againstsubType
- the sub type to checkmessage
- a message which will be prepended to the message produced by the function itself, and which may be
used to provide context. It should normally end in a ": " or ". " so that the function generate message
looks ok when appended to it.inserts
- any inserts to include if the message is a format string.
java.lang.IllegalArgumentException
- if the classes are not assignable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |