|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.junit.Assert
public class Assert
A set of assertion methods useful for writing tests. Only failed assertions are recorded.
These methods can be used directly: Assert.assertEquals(...)
, however, they
read better if they are referenced through static import:
import static org.junit.Assert.*; ... assertEquals(...);
AssertionError
Constructor Summary | |
---|---|
protected |
Assert()
Protect constructor since it is a static only class |
Method Summary | ||
---|---|---|
static void |
assertArrayEquals(byte[] expecteds,
byte[] actuals)
Asserts that two byte arrays are equal. |
|
static void |
assertArrayEquals(char[] expecteds,
char[] actuals)
Asserts that two char arrays are equal. |
|
static void |
assertArrayEquals(int[] expecteds,
int[] actuals)
Asserts that two int arrays are equal. |
|
static void |
assertArrayEquals(long[] expecteds,
long[] actuals)
Asserts that two long arrays are equal. |
|
static void |
assertArrayEquals(java.lang.Object[] expecteds,
java.lang.Object[] actuals)
Asserts that two object arrays are equal. |
|
static void |
assertArrayEquals(short[] expecteds,
short[] actuals)
Asserts that two short arrays are equal. |
|
static void |
assertArrayEquals(java.lang.String message,
byte[] expecteds,
byte[] actuals)
Asserts that two byte arrays are equal. |
|
static void |
assertArrayEquals(java.lang.String message,
char[] expecteds,
char[] actuals)
Asserts that two char arrays are equal. |
|
static void |
assertArrayEquals(java.lang.String message,
int[] expecteds,
int[] actuals)
Asserts that two int arrays are equal. |
|
static void |
assertArrayEquals(java.lang.String message,
long[] expecteds,
long[] actuals)
Asserts that two long arrays are equal. |
|
static void |
assertArrayEquals(java.lang.String message,
java.lang.Object[] expecteds,
java.lang.Object[] actuals)
Asserts that two object arrays are equal. |
|
static void |
assertArrayEquals(java.lang.String message,
short[] expecteds,
short[] actuals)
Asserts that two short arrays are equal. |
|
static void |
assertEquals(double expected,
double actual)
|
|
static void |
assertEquals(double expected,
double actual,
double delta)
Asserts that two doubles or floats are equal to within a positive delta. |
|
static void |
assertEquals(long expected,
long actual)
|
|
static void |
assertEquals(java.lang.Object[] expecteds,
java.lang.Object[] actuals)
Deprecated. use assertArrayEquals |
|
static void |
assertEquals(java.lang.Object expected,
java.lang.Object actual)
Asserts that two objects are equal. |
|
static void |
assertEquals(java.lang.String message,
double expected,
double actual)
|
|
static void |
assertEquals(java.lang.String message,
double expected,
double actual,
double delta)
Asserts that two doubles or floats are equal to within a positive delta. |
|
static void |
assertEquals(java.lang.String message,
long expected,
long actual)
|
|
static void |
assertEquals(java.lang.String message,
java.lang.Object[] expecteds,
java.lang.Object[] actuals)
Deprecated. use assertArrayEquals |
|
static void |
assertEquals(java.lang.String message,
java.lang.Object expected,
java.lang.Object actual)
Asserts that two objects are equal. |
|
static void |
assertFalse(boolean condition)
Asserts that a condition is false. |
|
static void |
assertFalse(java.lang.String message,
boolean condition)
Asserts that a condition is false. |
|
static void |
assertNotNull(java.lang.Object object)
Asserts that an object isn't null. |
|
static void |
assertNotNull(java.lang.String message,
java.lang.Object object)
Asserts that an object isn't null. |
|
static void |
assertNotSame(java.lang.Object unexpected,
java.lang.Object actual)
Asserts that two objects do not refer to the same object. |
|
static void |
assertNotSame(java.lang.String message,
java.lang.Object unexpected,
java.lang.Object actual)
Asserts that two objects do not refer to the same object. |
|
static void |
assertNull(java.lang.Object object)
Asserts that an object is null. |
|
static void |
assertNull(java.lang.String message,
java.lang.Object object)
Asserts that an object is null. |
|
static void |
assertSame(java.lang.Object expected,
java.lang.Object actual)
Asserts that two objects refer to the same object. |
|
static void |
assertSame(java.lang.String message,
java.lang.Object expected,
java.lang.Object actual)
Asserts that two objects refer to the same object. |
|
static
|
assertThat(java.lang.String reason,
T actual,
org.hamcrest.Matcher<T> matcher)
|
|
static
|
assertThat(T actual,
org.hamcrest.Matcher<T> matcher)
|
|
static void |
assertTrue(boolean condition)
Asserts that a condition is true. |
|
static void |
assertTrue(java.lang.String message,
boolean condition)
Asserts that a condition is true. |
|
static void |
fail()
Fails a test with no message. |
|
static void |
fail(java.lang.String message)
Fails a test with the given message. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected Assert()
Method Detail |
---|
public static void assertTrue(java.lang.String message, boolean condition)
AssertionError
with the given message.
message
- the identifying message or null
for the AssertionError
condition
- condition to be checkedpublic static void assertTrue(boolean condition)
AssertionError
without a message.
condition
- condition to be checkedpublic static void assertFalse(java.lang.String message, boolean condition)
AssertionError
with the given message.
message
- the identifying message or null
for the AssertionError
condition
- condition to be checkedpublic static void assertFalse(boolean condition)
AssertionError
without a message.
condition
- condition to be checkedpublic static void fail(java.lang.String message)
message
- the identifying message or null
for the AssertionError
AssertionError
public static void fail()
public static void assertEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
AssertionError
is thrown with the given message. If expected
and actual
are null
, they are considered equal.
message
- the identifying message or null
for the AssertionError
expected
- expected valueactual
- actual valuepublic static void assertEquals(java.lang.Object expected, java.lang.Object actual)
AssertionError
without a message is thrown. If expected
and actual
are null
, they are considered equal.
expected
- expected valueactual
- the value to check against expected
public static void assertArrayEquals(java.lang.String message, java.lang.Object[] expecteds, java.lang.Object[] actuals) throws org.junit.internal.ArrayComparisonFailure
AssertionError
is thrown with the given message. If expecteds
and
actuals
are null
, they are considered equal.
message
- the identifying message or null
for the AssertionError
expecteds
- Object array or array of arrays (multi-dimensional array) with expected values.actuals
- Object array or array of arrays (multi-dimensional array) with actual values
org.junit.internal.ArrayComparisonFailure
public static void assertArrayEquals(java.lang.Object[] expecteds, java.lang.Object[] actuals)
AssertionError
is thrown. If expected
and actual
are null
,
they are considered equal.
expecteds
- Object array or array of arrays (multi-dimensional array) with expected valuesactuals
- Object array or array of arrays (multi-dimensional array) with actual valuespublic static void assertArrayEquals(java.lang.String message, byte[] expecteds, byte[] actuals) throws org.junit.internal.ArrayComparisonFailure
AssertionError
is thrown with the given message.
message
- the identifying message or null
for the AssertionError
expecteds
- byte array with expected values.actuals
- byte array with actual values
org.junit.internal.ArrayComparisonFailure
public static void assertArrayEquals(byte[] expecteds, byte[] actuals)
AssertionError
is thrown.
expecteds
- byte array with expected values.actuals
- byte array with actual valuespublic static void assertArrayEquals(java.lang.String message, char[] expecteds, char[] actuals) throws org.junit.internal.ArrayComparisonFailure
AssertionError
is thrown with the given message.
message
- the identifying message or null
for the AssertionError
expecteds
- char array with expected values.actuals
- char array with actual values
org.junit.internal.ArrayComparisonFailure
public static void assertArrayEquals(char[] expecteds, char[] actuals)
AssertionError
is thrown.
expecteds
- char array with expected values.actuals
- char array with actual valuespublic static void assertArrayEquals(java.lang.String message, short[] expecteds, short[] actuals) throws org.junit.internal.ArrayComparisonFailure
AssertionError
is thrown with the given message.
message
- the identifying message or null
for the AssertionError
expecteds
- short array with expected values.actuals
- short array with actual values
org.junit.internal.ArrayComparisonFailure
public static void assertArrayEquals(short[] expecteds, short[] actuals)
AssertionError
is thrown.
expecteds
- short array with expected values.actuals
- short array with actual valuespublic static void assertArrayEquals(java.lang.String message, int[] expecteds, int[] actuals) throws org.junit.internal.ArrayComparisonFailure
AssertionError
is thrown with the given message.
message
- the identifying message or null
for the AssertionError
expecteds
- int array with expected values.actuals
- int array with actual values
org.junit.internal.ArrayComparisonFailure
public static void assertArrayEquals(int[] expecteds, int[] actuals)
AssertionError
is thrown.
expecteds
- int array with expected values.actuals
- int array with actual valuespublic static void assertArrayEquals(java.lang.String message, long[] expecteds, long[] actuals) throws org.junit.internal.ArrayComparisonFailure
AssertionError
is thrown with the given message.
message
- the identifying message or null
for the AssertionError
expecteds
- long array with expected values.actuals
- long array with actual values
org.junit.internal.ArrayComparisonFailure
public static void assertArrayEquals(long[] expecteds, long[] actuals)
AssertionError
is thrown.
expecteds
- long array with expected values.actuals
- long array with actual valuespublic static void assertEquals(java.lang.String message, double expected, double actual, double delta)
AssertionError
is thrown with the given message. If the
expected value is infinity then the delta value is ignored. NaNs are
considered equal:
assertEquals(Double.NaN, Double.NaN, *)
passes
message
- the identifying message or null
for the AssertionError
expected
- expected valueactual
- the value to check against expected
delta
- the maximum delta between expected
and actual
for which
both numbers are still considered equal.public static void assertEquals(long expected, long actual)
public static void assertEquals(java.lang.String message, long expected, long actual)
public static void assertEquals(double expected, double actual)
public static void assertEquals(java.lang.String message, double expected, double actual)
public static void assertEquals(double expected, double actual, double delta)
AssertionError
is thrown. If the
expected value is infinity then the delta value is ignored.NaNs are
considered equal:
assertEquals(Double.NaN, Double.NaN, *)
passes
expected
- expected valueactual
- the value to check against expected
delta
- the maximum delta between expected
and actual
for which
both numbers are still considered equal.public static void assertNotNull(java.lang.String message, java.lang.Object object)
AssertionError
is
thrown with the given message.
message
- the identifying message or null
for the AssertionError
object
- Object to check or null
public static void assertNotNull(java.lang.Object object)
AssertionError
is
thrown.
object
- Object to check or null
public static void assertNull(java.lang.String message, java.lang.Object object)
AssertionError
is
thrown with the given message.
message
- the identifying message or null
for the AssertionError
object
- Object to check or null
public static void assertNull(java.lang.Object object)
AssertionError
is
thrown.
object
- Object to check or null
public static void assertSame(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
AssertionError
is thrown with the given message.
message
- the identifying message or null
for the AssertionError
expected
- the expected objectactual
- the object to compare to expected
public static void assertSame(java.lang.Object expected, java.lang.Object actual)
AssertionError
without a message is thrown.
expected
- the expected objectactual
- the object to compare to expected
public static void assertNotSame(java.lang.String message, java.lang.Object unexpected, java.lang.Object actual)
AssertionError
is thrown with the given
message.
message
- the identifying message or null
for the AssertionError
unexpected
- the object you don't expectactual
- the object to compare to unexpected
public static void assertNotSame(java.lang.Object unexpected, java.lang.Object actual)
AssertionError
without a message is thrown.
unexpected
- the object you don't expectactual
- the object to compare to unexpected
@Deprecated public static void assertEquals(java.lang.String message, java.lang.Object[] expecteds, java.lang.Object[] actuals)
AssertionError
is thrown with the given message. If expecteds
and
actuals
are null
, they are considered equal.
message
- the identifying message or null
for the AssertionError
expecteds
- Object array or array of arrays (multi-dimensional array) with expected values.actuals
- Object array or array of arrays (multi-dimensional array) with actual values@Deprecated public static void assertEquals(java.lang.Object[] expecteds, java.lang.Object[] actuals)
AssertionError
is thrown. If expected
and actual
are null
,
they are considered equal.
expecteds
- Object array or array of arrays (multi-dimensional array) with expected valuesactuals
- Object array or array of arrays (multi-dimensional array) with actual valuespublic static <T> void assertThat(T actual, org.hamcrest.Matcher<T> matcher)
public static <T> void assertThat(java.lang.String reason, T actual, org.hamcrest.Matcher<T> matcher)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |