public final class Asserts
extends java.lang.Object
assert
keyword, these checks
can not and should not be turned off.
See Sun's assert specification for recommended best practices.
Modifier and Type | Method and Description |
---|---|
static void |
assertContains(java.util.Collection coll,
java.lang.Object elem)
Assert that
coll contains elem |
static void |
assertEquals(int expected,
int actual)
Verify that two values are equal.
|
static void |
assertEquals(int expected,
int actual,
java.lang.String expectedLabel,
java.lang.String actualLabel)
Verify that two values are equal.
|
static void |
assertEquals(java.lang.Object expected,
java.lang.Object actual)
Verify that two values are equal (according to their equals method,
unless expected is null, then according to ==).
|
static void |
assertEquals(java.lang.Object expected,
java.lang.Object actual,
java.lang.String expectedLabel,
java.lang.String actualLabel)
Verify that two values are equal (according to their equals method,
unless expected is null, then according to ==).
|
static void |
assertNotEmpty(java.lang.String s)
Verify that a string is not empty and throw a runtime exception if so.
|
static void |
assertNotEmpty(java.lang.String s,
java.lang.String label)
Verify that a string is not empty and throw a runtime exception if so.
|
static void |
assertNotNull(java.lang.Object o)
Verify that a parameter is not null and throw a runtime exception if so.
|
static void |
assertNotNull(java.lang.Object o,
java.lang.String label)
Verify that a parameter is not null and throw a runtime exception if so.
|
static void |
assertTrue(boolean cond)
Assert that an arbitrary condition is true and throw an exception if the
condition is false.
|
static void |
assertTrue(boolean cond,
java.lang.String msg)
Assert that an arbitrary condition is true throw an exception with
message
msg if the condition is false. |
static void |
fail(java.lang.String msg)
This is the equivalent of assertTrue(false, msg).
|
public static void assertTrue(boolean cond) throws java.lang.IllegalStateException
cond
- condition to assertjava.lang.IllegalStateException
- if condition is false
public static void assertTrue(boolean cond, java.lang.String msg) throws java.lang.IllegalStateException
msg
if the condition is false.cond
- condition to assertmsg
- failure messagejava.lang.IllegalStateException
- if condition is false
public static void assertNotNull(java.lang.Object o) throws java.lang.IllegalStateException
o
- the object that should not be null
java.lang.IllegalStateException
- if o
is nullpublic static void assertNotNull(java.lang.Object o, java.lang.String label) throws java.lang.IllegalStateException
o
- the object that should not be null
label
- the label for o
to include in the error
messagejava.lang.IllegalStateException
- if o
is nullpublic static void assertNotEmpty(java.lang.String s) throws java.lang.IllegalStateException
s
- the string to check for emptinessjava.lang.IllegalStateException
- if s
is an empty stringpublic static void assertNotEmpty(java.lang.String s, java.lang.String label) throws java.lang.IllegalStateException
s
- the string to check for emptinesslabel
- the label for s
to include in the error
messagejava.lang.IllegalStateException
- if s
is an empty stringpublic static void assertEquals(java.lang.Object expected, java.lang.Object actual) throws java.lang.IllegalStateException
expected
- Expected value.actual
- Actual value.java.lang.IllegalStateException
- if expected
is not
equal to actual
public static void assertEquals(java.lang.Object expected, java.lang.Object actual, java.lang.String expectedLabel, java.lang.String actualLabel) throws java.lang.IllegalStateException
expected
- Expected value.actual
- Actual value.expectedLabel
- Label for first (generally expected) value.actualLabel
- Label for second (generally actual) value.java.lang.IllegalStateException
- condition was falsepublic static void assertEquals(int expected, int actual) throws java.lang.IllegalStateException
expected
- Expected value.actual
- Actual value.java.lang.IllegalStateException
- if expected != actual
public static void assertEquals(int expected, int actual, java.lang.String expectedLabel, java.lang.String actualLabel) throws java.lang.IllegalStateException
expected
- Expected value.actual
- Actual value.expectedLabel
- Label for first (generally expected) value.actualLabel
- Label for second (generally actual) value.java.lang.IllegalStateException
- if expected != actual
public static void assertContains(java.util.Collection coll, java.lang.Object elem)
coll
contains elem
coll
- a collectionelem
- the element that should be in the collectionpublic static void fail(java.lang.String msg) throws java.lang.IllegalStateException
msg
- A string describing the condition of failure.java.lang.IllegalStateException
- always