Package org.junit
Class Assert
- java.lang.Object
-
- org.junit.Assert
-
public class Assert extends java.lang.Object
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(...);
- Since:
- 4.0
- See Also:
AssertionError
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Assert()
Protect constructor since it is a static only class
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
assertArrayEquals(boolean[] expecteds, boolean[] actuals)
Asserts that two boolean arrays are equal.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(double[] expecteds, double[] actuals, double delta)
Asserts that two double arrays are equal.static void
assertArrayEquals(float[] expecteds, float[] actuals, float delta)
Asserts that two float 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(short[] expecteds, short[] actuals)
Asserts that two short arrays are equal.static void
assertArrayEquals(java.lang.Object[] expecteds, java.lang.Object[] actuals)
Asserts that two object arrays are equal.static void
assertArrayEquals(java.lang.String message, boolean[] expecteds, boolean[] actuals)
Asserts that two boolean 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, double[] expecteds, double[] actuals, double delta)
Asserts that two double arrays are equal.static void
assertArrayEquals(java.lang.String message, float[] expecteds, float[] actuals, float delta)
Asserts that two float 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, short[] expecteds, short[] actuals)
Asserts that two short 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
assertEquals(double expected, double actual)
Deprecated.UseassertEquals(double expected, double actual, double delta)
insteadstatic void
assertEquals(double expected, double actual, double delta)
Asserts that two doubles are equal to within a positive delta.static void
assertEquals(float expected, float actual, float delta)
Asserts that two floats are equal to within a positive delta.static void
assertEquals(long expected, long actual)
Asserts that two longs are equal.static void
assertEquals(java.lang.Object[] expecteds, java.lang.Object[] actuals)
Deprecated.use assertArrayEqualsstatic 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)
Deprecated.UseassertEquals(String message, double expected, double actual, double delta)
insteadstatic void
assertEquals(java.lang.String message, double expected, double actual, double delta)
Asserts that two doubles are equal to within a positive delta.static void
assertEquals(java.lang.String message, float expected, float actual, float delta)
Asserts that two floats are equal to within a positive delta.static void
assertEquals(java.lang.String message, long expected, long actual)
Asserts that two longs are equal.static void
assertEquals(java.lang.String message, java.lang.Object[] expecteds, java.lang.Object[] actuals)
Deprecated.use assertArrayEqualsstatic 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
assertNotEquals(double unexpected, double actual, double delta)
Asserts that two doubles are not equal to within a positive delta.static void
assertNotEquals(float unexpected, float actual, float delta)
Asserts that two floats are not equal to within a positive delta.static void
assertNotEquals(long unexpected, long actual)
Asserts that two longs are not equals.static void
assertNotEquals(java.lang.Object unexpected, java.lang.Object actual)
Asserts that two objects are not equals.static void
assertNotEquals(java.lang.String message, double unexpected, double actual, double delta)
Asserts that two doubles are not equal to within a positive delta.static void
assertNotEquals(java.lang.String message, float unexpected, float actual, float delta)
Asserts that two floats are not equal to within a positive delta.static void
assertNotEquals(java.lang.String message, long unexpected, long actual)
Asserts that two longs are not equals.static void
assertNotEquals(java.lang.String message, java.lang.Object unexpected, java.lang.Object actual)
Asserts that two objects are not equals.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 <T> void
assertThat(java.lang.String reason, T actual, org.hamcrest.Matcher<? super T> matcher)
Deprecated.useorg.hamcrest.MatcherAssert.assertThat()
static <T> void
assertThat(T actual, org.hamcrest.Matcher<? super T> matcher)
Deprecated.useorg.hamcrest.MatcherAssert.assertThat()
static <T extends java.lang.Throwable>
TassertThrows(java.lang.Class<T> expectedThrowable, ThrowingRunnable runnable)
Asserts thatrunnable
throws an exception of typeexpectedThrowable
when executed.static <T extends java.lang.Throwable>
TassertThrows(java.lang.String message, java.lang.Class<T> expectedThrowable, ThrowingRunnable runnable)
Asserts thatrunnable
throws an exception of typeexpectedThrowable
when executed.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.
-
-
-
Constructor Detail
-
Assert
protected Assert()
Protect constructor since it is a static only class
-
-
Method Detail
-
assertTrue
public static void assertTrue(java.lang.String message, boolean condition)
Asserts that a condition is true. If it isn't it throws anAssertionError
with the given message.- Parameters:
message
- the identifying message for theAssertionError
(null
okay)condition
- condition to be checked
-
assertTrue
public static void assertTrue(boolean condition)
Asserts that a condition is true. If it isn't it throws anAssertionError
without a message.- Parameters:
condition
- condition to be checked
-
assertFalse
public static void assertFalse(java.lang.String message, boolean condition)
Asserts that a condition is false. If it isn't it throws anAssertionError
with the given message.- Parameters:
message
- the identifying message for theAssertionError
(null
okay)condition
- condition to be checked
-
assertFalse
public static void assertFalse(boolean condition)
Asserts that a condition is false. If it isn't it throws anAssertionError
without a message.- Parameters:
condition
- condition to be checked
-
fail
public static void fail(java.lang.String message)
Fails a test with the given message.- Parameters:
message
- the identifying message for theAssertionError
(null
okay)- See Also:
AssertionError
-
fail
public static void fail()
Fails a test with no message.
-
assertEquals
public static void assertEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
Asserts that two objects are equal. If they are not, anAssertionError
is thrown with the given message. Ifexpected
andactual
arenull
, they are considered equal.- Parameters:
message
- the identifying message for theAssertionError
(null
okay)expected
- expected valueactual
- actual value
-
assertEquals
public static void assertEquals(java.lang.Object expected, java.lang.Object actual)
Asserts that two objects are equal. If they are not, anAssertionError
without a message is thrown. Ifexpected
andactual
arenull
, they are considered equal.- Parameters:
expected
- expected valueactual
- the value to check againstexpected
-
assertNotEquals
public static void assertNotEquals(java.lang.String message, java.lang.Object unexpected, java.lang.Object actual)
Asserts that two objects are not equals. If they are, anAssertionError
is thrown with the given message. Ifunexpected
andactual
arenull
, they are considered equal.- Parameters:
message
- the identifying message for theAssertionError
(null
okay)unexpected
- unexpected value to checkactual
- the value to check againstunexpected
-
assertNotEquals
public static void assertNotEquals(java.lang.Object unexpected, java.lang.Object actual)
Asserts that two objects are not equals. If they are, anAssertionError
without a message is thrown. Ifunexpected
andactual
arenull
, they are considered equal.- Parameters:
unexpected
- unexpected value to checkactual
- the value to check againstunexpected
-
assertNotEquals
public static void assertNotEquals(java.lang.String message, long unexpected, long actual)
Asserts that two longs are not equals. If they are, anAssertionError
is thrown with the given message.- Parameters:
message
- the identifying message for theAssertionError
(null
okay)unexpected
- unexpected value to checkactual
- the value to check againstunexpected
-
assertNotEquals
public static void assertNotEquals(long unexpected, long actual)
Asserts that two longs are not equals. If they are, anAssertionError
without a message is thrown.- Parameters:
unexpected
- unexpected value to checkactual
- the value to check againstunexpected
-
assertNotEquals
public static void assertNotEquals(java.lang.String message, double unexpected, double actual, double delta)
Asserts that two doubles are not equal to within a positive delta. If they are, anAssertionError
is thrown with the given message. If the unexpected value is infinity then the delta value is ignored. NaNs are considered equal:assertNotEquals(Double.NaN, Double.NaN, *)
fails- Parameters:
message
- the identifying message for theAssertionError
(null
okay)unexpected
- unexpected valueactual
- the value to check againstunexpected
delta
- the maximum delta betweenunexpected
andactual
for which both numbers are still considered equal.
-
assertNotEquals
public static void assertNotEquals(double unexpected, double actual, double delta)
Asserts that two doubles are not equal to within a positive delta. If they are, anAssertionError
is thrown. If the unexpected value is infinity then the delta value is ignored.NaNs are considered equal:assertNotEquals(Double.NaN, Double.NaN, *)
fails- Parameters:
unexpected
- unexpected valueactual
- the value to check againstunexpected
delta
- the maximum delta betweenunexpected
andactual
for which both numbers are still considered equal.
-
assertNotEquals
public static void assertNotEquals(float unexpected, float actual, float delta)
Asserts that two floats are not equal to within a positive delta. If they are, anAssertionError
is thrown. If the unexpected value is infinity then the delta value is ignored.NaNs are considered equal:assertNotEquals(Float.NaN, Float.NaN, *)
fails- Parameters:
unexpected
- unexpected valueactual
- the value to check againstunexpected
delta
- the maximum delta betweenunexpected
andactual
for which both numbers are still considered equal.
-
assertArrayEquals
public static void assertArrayEquals(java.lang.String message, java.lang.Object[] expecteds, java.lang.Object[] actuals) throws org.junit.internal.ArrayComparisonFailure
Asserts that two object arrays are equal. If they are not, anAssertionError
is thrown with the given message. Ifexpecteds
andactuals
arenull
, they are considered equal.- Parameters:
message
- the identifying message for theAssertionError
(null
okay)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- Throws:
org.junit.internal.ArrayComparisonFailure
-
assertArrayEquals
public static void assertArrayEquals(java.lang.Object[] expecteds, java.lang.Object[] actuals)
Asserts that two object arrays are equal. If they are not, anAssertionError
is thrown. Ifexpected
andactual
arenull
, they are considered equal.- Parameters:
expecteds
- Object array or array of arrays (multi-dimensional array) with expected valuesactuals
- Object array or array of arrays (multi-dimensional array) with actual values
-
assertArrayEquals
public static void assertArrayEquals(java.lang.String message, boolean[] expecteds, boolean[] actuals) throws org.junit.internal.ArrayComparisonFailure
Asserts that two boolean arrays are equal. If they are not, anAssertionError
is thrown with the given message. Ifexpecteds
andactuals
arenull
, they are considered equal.- Parameters:
message
- the identifying message for theAssertionError
(null
okay)expecteds
- boolean array with expected values.actuals
- boolean array with expected values.- Throws:
org.junit.internal.ArrayComparisonFailure
-
assertArrayEquals
public static void assertArrayEquals(boolean[] expecteds, boolean[] actuals)
Asserts that two boolean arrays are equal. If they are not, anAssertionError
is thrown. Ifexpected
andactual
arenull
, they are considered equal.- Parameters:
expecteds
- boolean array with expected values.actuals
- boolean array with expected values.
-
assertArrayEquals
public static void assertArrayEquals(java.lang.String message, byte[] expecteds, byte[] actuals) throws org.junit.internal.ArrayComparisonFailure
Asserts that two byte arrays are equal. If they are not, anAssertionError
is thrown with the given message.- Parameters:
message
- the identifying message for theAssertionError
(null
okay)expecteds
- byte array with expected values.actuals
- byte array with actual values- Throws:
org.junit.internal.ArrayComparisonFailure
-
assertArrayEquals
public static void assertArrayEquals(byte[] expecteds, byte[] actuals)
Asserts that two byte arrays are equal. If they are not, anAssertionError
is thrown.- Parameters:
expecteds
- byte array with expected values.actuals
- byte array with actual values
-
assertArrayEquals
public static void assertArrayEquals(java.lang.String message, char[] expecteds, char[] actuals) throws org.junit.internal.ArrayComparisonFailure
Asserts that two char arrays are equal. If they are not, anAssertionError
is thrown with the given message.- Parameters:
message
- the identifying message for theAssertionError
(null
okay)expecteds
- char array with expected values.actuals
- char array with actual values- Throws:
org.junit.internal.ArrayComparisonFailure
-
assertArrayEquals
public static void assertArrayEquals(char[] expecteds, char[] actuals)
Asserts that two char arrays are equal. If they are not, anAssertionError
is thrown.- Parameters:
expecteds
- char array with expected values.actuals
- char array with actual values
-
assertArrayEquals
public static void assertArrayEquals(java.lang.String message, short[] expecteds, short[] actuals) throws org.junit.internal.ArrayComparisonFailure
Asserts that two short arrays are equal. If they are not, anAssertionError
is thrown with the given message.- Parameters:
message
- the identifying message for theAssertionError
(null
okay)expecteds
- short array with expected values.actuals
- short array with actual values- Throws:
org.junit.internal.ArrayComparisonFailure
-
assertArrayEquals
public static void assertArrayEquals(short[] expecteds, short[] actuals)
Asserts that two short arrays are equal. If they are not, anAssertionError
is thrown.- Parameters:
expecteds
- short array with expected values.actuals
- short array with actual values
-
assertArrayEquals
public static void assertArrayEquals(java.lang.String message, int[] expecteds, int[] actuals) throws org.junit.internal.ArrayComparisonFailure
Asserts that two int arrays are equal. If they are not, anAssertionError
is thrown with the given message.- Parameters:
message
- the identifying message for theAssertionError
(null
okay)expecteds
- int array with expected values.actuals
- int array with actual values- Throws:
org.junit.internal.ArrayComparisonFailure
-
assertArrayEquals
public static void assertArrayEquals(int[] expecteds, int[] actuals)
Asserts that two int arrays are equal. If they are not, anAssertionError
is thrown.- Parameters:
expecteds
- int array with expected values.actuals
- int array with actual values
-
assertArrayEquals
public static void assertArrayEquals(java.lang.String message, long[] expecteds, long[] actuals) throws org.junit.internal.ArrayComparisonFailure
Asserts that two long arrays are equal. If they are not, anAssertionError
is thrown with the given message.- Parameters:
message
- the identifying message for theAssertionError
(null
okay)expecteds
- long array with expected values.actuals
- long array with actual values- Throws:
org.junit.internal.ArrayComparisonFailure
-
assertArrayEquals
public static void assertArrayEquals(long[] expecteds, long[] actuals)
Asserts that two long arrays are equal. If they are not, anAssertionError
is thrown.- Parameters:
expecteds
- long array with expected values.actuals
- long array with actual values
-
assertArrayEquals
public static void assertArrayEquals(java.lang.String message, double[] expecteds, double[] actuals, double delta) throws org.junit.internal.ArrayComparisonFailure
Asserts that two double arrays are equal. If they are not, anAssertionError
is thrown with the given message.- Parameters:
message
- the identifying message for theAssertionError
(null
okay)expecteds
- double array with expected values.actuals
- double array with actual valuesdelta
- the maximum delta betweenexpecteds[i]
andactuals[i]
for which both numbers are still considered equal.- Throws:
org.junit.internal.ArrayComparisonFailure
-
assertArrayEquals
public static void assertArrayEquals(double[] expecteds, double[] actuals, double delta)
Asserts that two double arrays are equal. If they are not, anAssertionError
is thrown.- Parameters:
expecteds
- double array with expected values.actuals
- double array with actual valuesdelta
- the maximum delta betweenexpecteds[i]
andactuals[i]
for which both numbers are still considered equal.
-
assertArrayEquals
public static void assertArrayEquals(java.lang.String message, float[] expecteds, float[] actuals, float delta) throws org.junit.internal.ArrayComparisonFailure
Asserts that two float arrays are equal. If they are not, anAssertionError
is thrown with the given message.- Parameters:
message
- the identifying message for theAssertionError
(null
okay)expecteds
- float array with expected values.actuals
- float array with actual valuesdelta
- the maximum delta betweenexpecteds[i]
andactuals[i]
for which both numbers are still considered equal.- Throws:
org.junit.internal.ArrayComparisonFailure
-
assertArrayEquals
public static void assertArrayEquals(float[] expecteds, float[] actuals, float delta)
Asserts that two float arrays are equal. If they are not, anAssertionError
is thrown.- Parameters:
expecteds
- float array with expected values.actuals
- float array with actual valuesdelta
- the maximum delta betweenexpecteds[i]
andactuals[i]
for which both numbers are still considered equal.
-
assertEquals
public static void assertEquals(java.lang.String message, double expected, double actual, double delta)
Asserts that two doubles are equal to within a positive delta. If they are not, anAssertionError
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- Parameters:
message
- the identifying message for theAssertionError
(null
okay)expected
- expected valueactual
- the value to check againstexpected
delta
- the maximum delta betweenexpected
andactual
for which both numbers are still considered equal.
-
assertEquals
public static void assertEquals(java.lang.String message, float expected, float actual, float delta)
Asserts that two floats are equal to within a positive delta. If they are not, anAssertionError
is thrown with the given message. If the expected value is infinity then the delta value is ignored. NaNs are considered equal:assertEquals(Float.NaN, Float.NaN, *)
passes- Parameters:
message
- the identifying message for theAssertionError
(null
okay)expected
- expected valueactual
- the value to check againstexpected
delta
- the maximum delta betweenexpected
andactual
for which both numbers are still considered equal.
-
assertNotEquals
public static void assertNotEquals(java.lang.String message, float unexpected, float actual, float delta)
Asserts that two floats are not equal to within a positive delta. If they are, anAssertionError
is thrown with the given message. If the unexpected value is infinity then the delta value is ignored. NaNs are considered equal:assertNotEquals(Float.NaN, Float.NaN, *)
fails- Parameters:
message
- the identifying message for theAssertionError
(null
okay)unexpected
- unexpected valueactual
- the value to check againstunexpected
delta
- the maximum delta betweenunexpected
andactual
for which both numbers are still considered equal.
-
assertEquals
public static void assertEquals(long expected, long actual)
Asserts that two longs are equal. If they are not, anAssertionError
is thrown.- Parameters:
expected
- expected long value.actual
- actual long value
-
assertEquals
public static void assertEquals(java.lang.String message, long expected, long actual)
Asserts that two longs are equal. If they are not, anAssertionError
is thrown with the given message.- Parameters:
message
- the identifying message for theAssertionError
(null
okay)expected
- long expected value.actual
- long actual value
-
assertEquals
@Deprecated public static void assertEquals(double expected, double actual)
Deprecated.UseassertEquals(double expected, double actual, double delta)
instead
-
assertEquals
@Deprecated public static void assertEquals(java.lang.String message, double expected, double actual)
Deprecated.UseassertEquals(String message, double expected, double actual, double delta)
instead
-
assertEquals
public static void assertEquals(double expected, double actual, double delta)
Asserts that two doubles are equal to within a positive delta. If they are not, anAssertionError
is thrown. If the expected value is infinity then the delta value is ignored.NaNs are considered equal:assertEquals(Double.NaN, Double.NaN, *)
passes- Parameters:
expected
- expected valueactual
- the value to check againstexpected
delta
- the maximum delta betweenexpected
andactual
for which both numbers are still considered equal.
-
assertEquals
public static void assertEquals(float expected, float actual, float delta)
Asserts that two floats are equal to within a positive delta. If they are not, anAssertionError
is thrown. If the expected value is infinity then the delta value is ignored. NaNs are considered equal:assertEquals(Float.NaN, Float.NaN, *)
passes- Parameters:
expected
- expected valueactual
- the value to check againstexpected
delta
- the maximum delta betweenexpected
andactual
for which both numbers are still considered equal.
-
assertNotNull
public static void assertNotNull(java.lang.String message, java.lang.Object object)
Asserts that an object isn't null. If it is anAssertionError
is thrown with the given message.- Parameters:
message
- the identifying message for theAssertionError
(null
okay)object
- Object to check ornull
-
assertNotNull
public static void assertNotNull(java.lang.Object object)
Asserts that an object isn't null. If it is anAssertionError
is thrown.- Parameters:
object
- Object to check ornull
-
assertNull
public static void assertNull(java.lang.String message, java.lang.Object object)
Asserts that an object is null. If it is not, anAssertionError
is thrown with the given message.- Parameters:
message
- the identifying message for theAssertionError
(null
okay)object
- Object to check ornull
-
assertNull
public static void assertNull(java.lang.Object object)
Asserts that an object is null. If it isn't anAssertionError
is thrown.- Parameters:
object
- Object to check ornull
-
assertSame
public static void assertSame(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
Asserts that two objects refer to the same object. If they are not, anAssertionError
is thrown with the given message.- Parameters:
message
- the identifying message for theAssertionError
(null
okay)expected
- the expected objectactual
- the object to compare toexpected
-
assertSame
public static void assertSame(java.lang.Object expected, java.lang.Object actual)
Asserts that two objects refer to the same object. If they are not the same, anAssertionError
without a message is thrown.- Parameters:
expected
- the expected objectactual
- the object to compare toexpected
-
assertNotSame
public 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. If they do refer to the same object, anAssertionError
is thrown with the given message.- Parameters:
message
- the identifying message for theAssertionError
(null
okay)unexpected
- the object you don't expectactual
- the object to compare tounexpected
-
assertNotSame
public static void assertNotSame(java.lang.Object unexpected, java.lang.Object actual)
Asserts that two objects do not refer to the same object. If they do refer to the same object, anAssertionError
without a message is thrown.- Parameters:
unexpected
- the object you don't expectactual
- the object to compare tounexpected
-
assertEquals
@Deprecated public static void assertEquals(java.lang.String message, java.lang.Object[] expecteds, java.lang.Object[] actuals)
Deprecated.use assertArrayEqualsAsserts that two object arrays are equal. If they are not, anAssertionError
is thrown with the given message. Ifexpecteds
andactuals
arenull
, they are considered equal.- Parameters:
message
- the identifying message for theAssertionError
(null
okay)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
-
assertEquals
@Deprecated public static void assertEquals(java.lang.Object[] expecteds, java.lang.Object[] actuals)
Deprecated.use assertArrayEqualsAsserts that two object arrays are equal. If they are not, anAssertionError
is thrown. Ifexpected
andactual
arenull
, they are considered equal.- Parameters:
expecteds
- Object array or array of arrays (multi-dimensional array) with expected valuesactuals
- Object array or array of arrays (multi-dimensional array) with actual values
-
assertThat
@Deprecated public static <T> void assertThat(T actual, org.hamcrest.Matcher<? super T> matcher)
Deprecated.useorg.hamcrest.MatcherAssert.assertThat()
Asserts thatactual
satisfies the condition specified bymatcher
. If not, anAssertionError
is thrown with information about the matcher and failing value. Example:assertThat(0, is(1)); // fails: // failure message: // expected: is <1> // got value: <0> assertThat(0, is(not(1))) // passes
org.hamcrest.Matcher
does not currently document the meaning of its type parameterT
. This method assumes that a matcher typed asMatcher<T>
can be meaningfully applied only to values that could be assigned to a variable of typeT
.- Type Parameters:
T
- the static type accepted by the matcher (this can flag obvious compile-time problems such asassertThat(1, is("a"))
- Parameters:
actual
- the computed value being comparedmatcher
- an expression, built ofMatcher
s, specifying allowed values- See Also:
CoreMatchers
-
assertThat
@Deprecated public static <T> void assertThat(java.lang.String reason, T actual, org.hamcrest.Matcher<? super T> matcher)
Deprecated.useorg.hamcrest.MatcherAssert.assertThat()
Asserts thatactual
satisfies the condition specified bymatcher
. If not, anAssertionError
is thrown with the reason and information about the matcher and failing value. Example:assertThat("Help! Integers don't work", 0, is(1)); // fails: // failure message: // Help! Integers don't work // expected: is <1> // got value: <0> assertThat("Zero is one", 0, is(not(1))) // passes
org.hamcrest.Matcher
does not currently document the meaning of its type parameterT
. This method assumes that a matcher typed asMatcher<T>
can be meaningfully applied only to values that could be assigned to a variable of typeT
.- Type Parameters:
T
- the static type accepted by the matcher (this can flag obvious compile-time problems such asassertThat(1, is("a"))
- Parameters:
reason
- additional information about the erroractual
- the computed value being comparedmatcher
- an expression, built ofMatcher
s, specifying allowed values- See Also:
CoreMatchers
-
assertThrows
public static <T extends java.lang.Throwable> T assertThrows(java.lang.Class<T> expectedThrowable, ThrowingRunnable runnable)
Asserts thatrunnable
throws an exception of typeexpectedThrowable
when executed. If it does, the exception object is returned. If it does not throw an exception, anAssertionError
is thrown. If it throws the wrong type of exception, anAssertionError
is thrown describing the mismatch; the exception that was actually thrown can be obtained by callingThrowable.getCause()
.- Parameters:
expectedThrowable
- the expected type of the exceptionrunnable
- a function that is expected to throw an exception when executed- Returns:
- the exception thrown by
runnable
- Since:
- 4.13
-
assertThrows
public static <T extends java.lang.Throwable> T assertThrows(java.lang.String message, java.lang.Class<T> expectedThrowable, ThrowingRunnable runnable)
Asserts thatrunnable
throws an exception of typeexpectedThrowable
when executed. If it does, the exception object is returned. If it does not throw an exception, anAssertionError
is thrown. If it throws the wrong type of exception, anAssertionError
is thrown describing the mismatch; the exception that was actually thrown can be obtained by callingThrowable.getCause()
.- Parameters:
message
- the identifying message for theAssertionError
(null
okay)expectedThrowable
- the expected type of the exceptionrunnable
- a function that is expected to throw an exception when executed- Returns:
- the exception thrown by
runnable
- Since:
- 4.13
-
-