Package org.junit
Class Assert
java.lang.Object
org.junit.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(...);
- Since:
- 4.0
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAssert()Protect constructor since it is a static only class -
Method Summary
Modifier and TypeMethodDescriptionstatic voidassertArrayEquals(boolean[] expecteds, boolean[] actuals) Asserts that two boolean arrays are equal.static voidassertArrayEquals(byte[] expecteds, byte[] actuals) Asserts that two byte arrays are equal.static voidassertArrayEquals(char[] expecteds, char[] actuals) Asserts that two char arrays are equal.static voidassertArrayEquals(double[] expecteds, double[] actuals, double delta) Asserts that two double arrays are equal.static voidassertArrayEquals(float[] expecteds, float[] actuals, float delta) Asserts that two float arrays are equal.static voidassertArrayEquals(int[] expecteds, int[] actuals) Asserts that two int arrays are equal.static voidassertArrayEquals(long[] expecteds, long[] actuals) Asserts that two long arrays are equal.static voidassertArrayEquals(short[] expecteds, short[] actuals) Asserts that two short arrays are equal.static voidassertArrayEquals(Object[] expecteds, Object[] actuals) Asserts that two object arrays are equal.static voidassertArrayEquals(String message, boolean[] expecteds, boolean[] actuals) Asserts that two boolean arrays are equal.static voidassertArrayEquals(String message, byte[] expecteds, byte[] actuals) Asserts that two byte arrays are equal.static voidassertArrayEquals(String message, char[] expecteds, char[] actuals) Asserts that two char arrays are equal.static voidassertArrayEquals(String message, double[] expecteds, double[] actuals, double delta) Asserts that two double arrays are equal.static voidassertArrayEquals(String message, float[] expecteds, float[] actuals, float delta) Asserts that two float arrays are equal.static voidassertArrayEquals(String message, int[] expecteds, int[] actuals) Asserts that two int arrays are equal.static voidassertArrayEquals(String message, long[] expecteds, long[] actuals) Asserts that two long arrays are equal.static voidassertArrayEquals(String message, short[] expecteds, short[] actuals) Asserts that two short arrays are equal.static voidassertArrayEquals(String message, Object[] expecteds, Object[] actuals) Asserts that two object arrays are equal.static voidassertEquals(double expected, double actual) Deprecated.static voidassertEquals(double expected, double actual, double delta) Asserts that two doubles are equal to within a positive delta.static voidassertEquals(float expected, float actual, float delta) Asserts that two floats are equal to within a positive delta.static voidassertEquals(long expected, long actual) Asserts that two longs are equal.static voidassertEquals(Object[] expecteds, Object[] actuals) Deprecated.use assertArrayEqualsstatic voidassertEquals(Object expected, Object actual) Asserts that two objects are equal.static voidassertEquals(String message, double expected, double actual) Deprecated.UseassertEquals(String message, double expected, double actual, double delta)insteadstatic voidassertEquals(String message, double expected, double actual, double delta) Asserts that two doubles are equal to within a positive delta.static voidassertEquals(String message, float expected, float actual, float delta) Asserts that two floats are equal to within a positive delta.static voidassertEquals(String message, long expected, long actual) Asserts that two longs are equal.static voidassertEquals(String message, Object[] expecteds, Object[] actuals) Deprecated.use assertArrayEqualsstatic voidassertEquals(String message, Object expected, Object actual) Asserts that two objects are equal.static voidassertFalse(boolean condition) Asserts that a condition is false.static voidassertFalse(String message, boolean condition) Asserts that a condition is false.static voidassertNotEquals(double unexpected, double actual, double delta) Asserts that two doubles are not equal to within a positive delta.static voidassertNotEquals(float unexpected, float actual, float delta) Asserts that two floats are not equal to within a positive delta.static voidassertNotEquals(long unexpected, long actual) Asserts that two longs are not equals.static voidassertNotEquals(Object unexpected, Object actual) Asserts that two objects are not equals.static voidassertNotEquals(String message, double unexpected, double actual, double delta) Asserts that two doubles are not equal to within a positive delta.static voidassertNotEquals(String message, float unexpected, float actual, float delta) Asserts that two floats are not equal to within a positive delta.static voidassertNotEquals(String message, long unexpected, long actual) Asserts that two longs are not equals.static voidassertNotEquals(String message, Object unexpected, Object actual) Asserts that two objects are not equals.static voidassertNotNull(Object object) Asserts that an object isn't null.static voidassertNotNull(String message, Object object) Asserts that an object isn't null.static voidassertNotSame(Object unexpected, Object actual) Asserts that two objects do not refer to the same object.static voidassertNotSame(String message, Object unexpected, Object actual) Asserts that two objects do not refer to the same object.static voidassertNull(Object object) Asserts that an object is null.static voidassertNull(String message, Object object) Asserts that an object is null.static voidassertSame(Object expected, Object actual) Asserts that two objects refer to the same object.static voidassertSame(String message, Object expected, Object actual) Asserts that two objects refer to the same object.static <T> voidassertThat(String reason, T actual, org.hamcrest.Matcher<? super T> matcher) Deprecated.useorg.hamcrest.MatcherAssert.assertThat()static <T> voidassertThat(T actual, org.hamcrest.Matcher<? super T> matcher) Deprecated.useorg.hamcrest.MatcherAssert.assertThat()static <T extends Throwable>
TassertThrows(Class<T> expectedThrowable, ThrowingRunnable runnable) Asserts thatrunnablethrows an exception of typeexpectedThrowablewhen executed.static <T extends Throwable>
TassertThrows(String message, Class<T> expectedThrowable, ThrowingRunnable runnable) Asserts thatrunnablethrows an exception of typeexpectedThrowablewhen executed.static voidassertTrue(boolean condition) Asserts that a condition is true.static voidassertTrue(String message, boolean condition) Asserts that a condition is true.private static StringbuildPrefix(String message) private static booleandoubleIsDifferent(double d1, double d2, double delta) private static booleanequalsRegardingNull(Object expected, Object actual) static voidfail()Fails a test with no message.static voidFails a test with the given message.private static voidfailEquals(String message, Object actual) private static voidfailNotEquals(String message, Object expected, Object actual) private static voidfailNotNull(String message, Object actual) private static voidfailNotSame(String message, Object expected, Object actual) private static voidprivate static booleanfloatIsDifferent(float f1, float f2, float delta) (package private) static Stringprivate static StringformatClass(Class<?> value) private static StringformatClassAndValue(Object value, String valueString) private static voidinternalArrayEquals(String message, Object expecteds, Object actuals) Asserts that two object arrays are equal.private static boolean
-
Constructor Details
-
Assert
protected Assert()Protect constructor since it is a static only class
-
-
Method Details
-
assertTrue
Asserts that a condition is true. If it isn't it throws anAssertionErrorwith the given message.- Parameters:
message- the identifying message for theAssertionError(nullokay)condition- condition to be checked
-
assertTrue
public static void assertTrue(boolean condition) Asserts that a condition is true. If it isn't it throws anAssertionErrorwithout a message.- Parameters:
condition- condition to be checked
-
assertFalse
Asserts that a condition is false. If it isn't it throws anAssertionErrorwith the given message.- Parameters:
message- the identifying message for theAssertionError(nullokay)condition- condition to be checked
-
assertFalse
public static void assertFalse(boolean condition) Asserts that a condition is false. If it isn't it throws anAssertionErrorwithout a message.- Parameters:
condition- condition to be checked
-
fail
Fails a test with the given message.- Parameters:
message- the identifying message for theAssertionError(nullokay)- See Also:
-
fail
public static void fail()Fails a test with no message. -
assertEquals
Asserts that two objects are equal. If they are not, anAssertionErroris thrown with the given message. Ifexpectedandactualarenull, they are considered equal.- Parameters:
message- the identifying message for theAssertionError(nullokay)expected- expected valueactual- actual value
-
equalsRegardingNull
-
isEquals
-
assertEquals
Asserts that two objects are equal. If they are not, anAssertionErrorwithout a message is thrown. Ifexpectedandactualarenull, they are considered equal.- Parameters:
expected- expected valueactual- the value to check againstexpected
-
assertNotEquals
Asserts that two objects are not equals. If they are, anAssertionErroris thrown with the given message. Ifunexpectedandactualarenull, they are considered equal.- Parameters:
message- the identifying message for theAssertionError(nullokay)unexpected- unexpected value to checkactual- the value to check againstunexpected
-
assertNotEquals
Asserts that two objects are not equals. If they are, anAssertionErrorwithout a message is thrown. Ifunexpectedandactualarenull, they are considered equal.- Parameters:
unexpected- unexpected value to checkactual- the value to check againstunexpected
-
failEquals
-
assertNotEquals
Asserts that two longs are not equals. If they are, anAssertionErroris thrown with the given message.- Parameters:
message- the identifying message for theAssertionError(nullokay)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, anAssertionErrorwithout a message is thrown.- Parameters:
unexpected- unexpected value to checkactual- the value to check againstunexpected
-
assertNotEquals
Asserts that two doubles are not equal to within a positive delta. If they are, anAssertionErroris 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(nullokay)unexpected- unexpected valueactual- the value to check againstunexpecteddelta- the maximum delta betweenunexpectedandactualfor 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, anAssertionErroris 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 againstunexpecteddelta- the maximum delta betweenunexpectedandactualfor 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, anAssertionErroris 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 againstunexpecteddelta- the maximum delta betweenunexpectedandactualfor which both numbers are still considered equal.
-
assertArrayEquals
public static void assertArrayEquals(String message, Object[] expecteds, Object[] actuals) throws ArrayComparisonFailure Asserts that two object arrays are equal. If they are not, anAssertionErroris thrown with the given message. Ifexpectedsandactualsarenull, they are considered equal.- Parameters:
message- the identifying message for theAssertionError(nullokay)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:
ArrayComparisonFailure
-
assertArrayEquals
Asserts that two object arrays are equal. If they are not, anAssertionErroris thrown. Ifexpectedandactualarenull, 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(String message, boolean[] expecteds, boolean[] actuals) throws ArrayComparisonFailure Asserts that two boolean arrays are equal. If they are not, anAssertionErroris thrown with the given message. Ifexpectedsandactualsarenull, they are considered equal.- Parameters:
message- the identifying message for theAssertionError(nullokay)expecteds- boolean array with expected values.actuals- boolean array with expected values.- Throws:
ArrayComparisonFailure
-
assertArrayEquals
public static void assertArrayEquals(boolean[] expecteds, boolean[] actuals) Asserts that two boolean arrays are equal. If they are not, anAssertionErroris thrown. Ifexpectedandactualarenull, they are considered equal.- Parameters:
expecteds- boolean array with expected values.actuals- boolean array with expected values.
-
assertArrayEquals
public static void assertArrayEquals(String message, byte[] expecteds, byte[] actuals) throws ArrayComparisonFailure Asserts that two byte arrays are equal. If they are not, anAssertionErroris thrown with the given message.- Parameters:
message- the identifying message for theAssertionError(nullokay)expecteds- byte array with expected values.actuals- byte array with actual values- Throws:
ArrayComparisonFailure
-
assertArrayEquals
public static void assertArrayEquals(byte[] expecteds, byte[] actuals) Asserts that two byte arrays are equal. If they are not, anAssertionErroris thrown.- Parameters:
expecteds- byte array with expected values.actuals- byte array with actual values
-
assertArrayEquals
public static void assertArrayEquals(String message, char[] expecteds, char[] actuals) throws ArrayComparisonFailure Asserts that two char arrays are equal. If they are not, anAssertionErroris thrown with the given message.- Parameters:
message- the identifying message for theAssertionError(nullokay)expecteds- char array with expected values.actuals- char array with actual values- Throws:
ArrayComparisonFailure
-
assertArrayEquals
public static void assertArrayEquals(char[] expecteds, char[] actuals) Asserts that two char arrays are equal. If they are not, anAssertionErroris thrown.- Parameters:
expecteds- char array with expected values.actuals- char array with actual values
-
assertArrayEquals
public static void assertArrayEquals(String message, short[] expecteds, short[] actuals) throws ArrayComparisonFailure Asserts that two short arrays are equal. If they are not, anAssertionErroris thrown with the given message.- Parameters:
message- the identifying message for theAssertionError(nullokay)expecteds- short array with expected values.actuals- short array with actual values- Throws:
ArrayComparisonFailure
-
assertArrayEquals
public static void assertArrayEquals(short[] expecteds, short[] actuals) Asserts that two short arrays are equal. If they are not, anAssertionErroris thrown.- Parameters:
expecteds- short array with expected values.actuals- short array with actual values
-
assertArrayEquals
public static void assertArrayEquals(String message, int[] expecteds, int[] actuals) throws ArrayComparisonFailure Asserts that two int arrays are equal. If they are not, anAssertionErroris thrown with the given message.- Parameters:
message- the identifying message for theAssertionError(nullokay)expecteds- int array with expected values.actuals- int array with actual values- Throws:
ArrayComparisonFailure
-
assertArrayEquals
public static void assertArrayEquals(int[] expecteds, int[] actuals) Asserts that two int arrays are equal. If they are not, anAssertionErroris thrown.- Parameters:
expecteds- int array with expected values.actuals- int array with actual values
-
assertArrayEquals
public static void assertArrayEquals(String message, long[] expecteds, long[] actuals) throws ArrayComparisonFailure Asserts that two long arrays are equal. If they are not, anAssertionErroris thrown with the given message.- Parameters:
message- the identifying message for theAssertionError(nullokay)expecteds- long array with expected values.actuals- long array with actual values- Throws:
ArrayComparisonFailure
-
assertArrayEquals
public static void assertArrayEquals(long[] expecteds, long[] actuals) Asserts that two long arrays are equal. If they are not, anAssertionErroris thrown.- Parameters:
expecteds- long array with expected values.actuals- long array with actual values
-
assertArrayEquals
public static void assertArrayEquals(String message, double[] expecteds, double[] actuals, double delta) throws ArrayComparisonFailure Asserts that two double arrays are equal. If they are not, anAssertionErroris thrown with the given message.- Parameters:
message- the identifying message for theAssertionError(nullokay)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:
ArrayComparisonFailure
-
assertArrayEquals
public static void assertArrayEquals(double[] expecteds, double[] actuals, double delta) Asserts that two double arrays are equal. If they are not, anAssertionErroris 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(String message, float[] expecteds, float[] actuals, float delta) throws ArrayComparisonFailure Asserts that two float arrays are equal. If they are not, anAssertionErroris thrown with the given message.- Parameters:
message- the identifying message for theAssertionError(nullokay)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:
ArrayComparisonFailure
-
assertArrayEquals
public static void assertArrayEquals(float[] expecteds, float[] actuals, float delta) Asserts that two float arrays are equal. If they are not, anAssertionErroris 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.
-
internalArrayEquals
private static void internalArrayEquals(String message, Object expecteds, Object actuals) throws ArrayComparisonFailure Asserts that two object arrays are equal. If they are not, anAssertionErroris thrown with the given message. Ifexpectedsandactualsarenull, they are considered equal.- Parameters:
message- the identifying message for theAssertionError(nullokay)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:
ArrayComparisonFailure
-
assertEquals
Asserts that two doubles are equal to within a positive delta. If they are not, anAssertionErroris 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(nullokay)expected- expected valueactual- the value to check againstexpecteddelta- the maximum delta betweenexpectedandactualfor which both numbers are still considered equal.
-
assertEquals
Asserts that two floats are equal to within a positive delta. If they are not, anAssertionErroris 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(nullokay)expected- expected valueactual- the value to check againstexpecteddelta- the maximum delta betweenexpectedandactualfor which both numbers are still considered equal.
-
assertNotEquals
Asserts that two floats are not equal to within a positive delta. If they are, anAssertionErroris 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(nullokay)unexpected- unexpected valueactual- the value to check againstunexpecteddelta- the maximum delta betweenunexpectedandactualfor which both numbers are still considered equal.
-
doubleIsDifferent
private static boolean doubleIsDifferent(double d1, double d2, double delta) -
floatIsDifferent
private static boolean floatIsDifferent(float f1, float f2, float delta) -
assertEquals
public static void assertEquals(long expected, long actual) Asserts that two longs are equal. If they are not, anAssertionErroris thrown.- Parameters:
expected- expected long value.actual- actual long value
-
assertEquals
Asserts that two longs are equal. If they are not, anAssertionErroris thrown with the given message.- Parameters:
message- the identifying message for theAssertionError(nullokay)expected- long expected value.actual- long actual value
-
assertEquals
Deprecated.UseassertEquals(double expected, double actual, double delta)instead -
assertEquals
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, anAssertionErroris 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 againstexpecteddelta- the maximum delta betweenexpectedandactualfor 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, anAssertionErroris 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 againstexpecteddelta- the maximum delta betweenexpectedandactualfor which both numbers are still considered equal.
-
assertNotNull
Asserts that an object isn't null. If it is anAssertionErroris thrown with the given message.- Parameters:
message- the identifying message for theAssertionError(nullokay)object- Object to check ornull
-
assertNotNull
Asserts that an object isn't null. If it is anAssertionErroris thrown.- Parameters:
object- Object to check ornull
-
assertNull
Asserts that an object is null. If it is not, anAssertionErroris thrown with the given message.- Parameters:
message- the identifying message for theAssertionError(nullokay)object- Object to check ornull
-
assertNull
Asserts that an object is null. If it isn't anAssertionErroris thrown.- Parameters:
object- Object to check ornull
-
failNotNull
-
assertSame
Asserts that two objects refer to the same object. If they are not, anAssertionErroris thrown with the given message.- Parameters:
message- the identifying message for theAssertionError(nullokay)expected- the expected objectactual- the object to compare toexpected
-
assertSame
Asserts that two objects refer to the same object. If they are not the same, anAssertionErrorwithout a message is thrown.- Parameters:
expected- the expected objectactual- the object to compare toexpected
-
assertNotSame
Asserts that two objects do not refer to the same object. If they do refer to the same object, anAssertionErroris thrown with the given message.- Parameters:
message- the identifying message for theAssertionError(nullokay)unexpected- the object you don't expectactual- the object to compare tounexpected
-
assertNotSame
Asserts that two objects do not refer to the same object. If they do refer to the same object, anAssertionErrorwithout a message is thrown.- Parameters:
unexpected- the object you don't expectactual- the object to compare tounexpected
-
failSame
-
failNotSame
-
failNotEquals
-
format
-
formatClass
-
formatClassAndValue
-
assertEquals
Deprecated.use assertArrayEqualsAsserts that two object arrays are equal. If they are not, anAssertionErroris thrown with the given message. Ifexpectedsandactualsarenull, they are considered equal.- Parameters:
message- the identifying message for theAssertionError(nullokay)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.use assertArrayEqualsAsserts that two object arrays are equal. If they are not, anAssertionErroris thrown. Ifexpectedandactualarenull, 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.useorg.hamcrest.MatcherAssert.assertThat()Asserts thatactualsatisfies the condition specified bymatcher. If not, anAssertionErroris 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))) // passesorg.hamcrest.Matcherdoes 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 ofMatchers, specifying allowed values- See Also:
-
assertThat
@Deprecated public static <T> void assertThat(String reason, T actual, org.hamcrest.Matcher<? super T> matcher) Deprecated.useorg.hamcrest.MatcherAssert.assertThat()Asserts thatactualsatisfies the condition specified bymatcher. If not, anAssertionErroris 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))) // passesorg.hamcrest.Matcherdoes 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 ofMatchers, specifying allowed values- See Also:
-
assertThrows
public static <T extends Throwable> T assertThrows(Class<T> expectedThrowable, ThrowingRunnable runnable) Asserts thatrunnablethrows an exception of typeexpectedThrowablewhen executed. If it does, the exception object is returned. If it does not throw an exception, anAssertionErroris thrown. If it throws the wrong type of exception, anAssertionErroris 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 Throwable> T assertThrows(String message, Class<T> expectedThrowable, ThrowingRunnable runnable) Asserts thatrunnablethrows an exception of typeexpectedThrowablewhen executed. If it does, the exception object is returned. If it does not throw an exception, anAssertionErroris thrown. If it throws the wrong type of exception, anAssertionErroris thrown describing the mismatch; the exception that was actually thrown can be obtained by callingThrowable.getCause().- Parameters:
message- the identifying message for theAssertionError(nullokay)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
-
buildPrefix
-
assertEquals(double expected, double actual, double delta)instead