@API(value=Maintained)
public final class Assertions
extends java.lang.Object
Assertions is a collection of utility methods that support
asserting conditions in tests. A failed assertion will
always throw AssertionFailedError or a subclass if specified.AssertionFailedError,
Assumptions| Modifier and Type | Method and Description |
|---|---|
static void |
assertAll(Executable... asserts)
Asserts that all assertions contained in
asserts do not fail. |
static void |
assertAll(java.lang.String heading,
Executable... asserts)
Asserts that all assertions contained in
asserts do not fail. |
static void |
assertEquals(java.lang.Object expected,
java.lang.Object actual)
Asserts that
expected and actual are equal. |
static void |
assertEquals(java.lang.Object expected,
java.lang.Object actual,
java.lang.String message)
Asserts that
expected and actual are equal. |
static void |
assertEquals(java.lang.Object expected,
java.lang.Object actual,
java.util.function.Supplier<java.lang.String> messageSupplier)
Asserts that
expected and actual are equal. |
static void |
assertFalse(boolean condition)
Asserts that
condition is not true. |
static void |
assertFalse(boolean condition,
java.lang.String message)
Asserts that
condition is not true. |
static void |
assertFalse(java.util.function.BooleanSupplier booleanSupplier)
Asserts that
condition supplied by booleanSupplier is not true. |
static void |
assertFalse(boolean condition,
java.util.function.Supplier<java.lang.String> messageSupplier)
Asserts that
condition is not true. |
static void |
assertFalse(java.util.function.BooleanSupplier booleanSupplier,
java.lang.String message)
Asserts that
condition supplied by booleanSupplier is not true. |
static void |
assertFalse(java.util.function.BooleanSupplier booleanSupplier,
java.util.function.Supplier<java.lang.String> messageSupplier)
Asserts that
condition supplied by booleanSupplier is not true. |
static void |
assertNotEquals(java.lang.Object unexpected,
java.lang.Object actual)
Asserts that
expected and actual are not equal. |
static void |
assertNotEquals(java.lang.Object unexpected,
java.lang.Object actual,
java.lang.String message)
Asserts that
expected and actual are not equal. |
static void |
assertNotEquals(java.lang.Object unexpected,
java.lang.Object actual,
java.util.function.Supplier<java.lang.String> messageSupplier)
Asserts that
expected and actual are not equal. |
static void |
assertNotNull(java.lang.Object actual)
Asserts that
actual is not null. |
static void |
assertNotNull(java.lang.Object actual,
java.lang.String message)
Asserts that
actual is not null. |
static void |
assertNotNull(java.lang.Object actual,
java.util.function.Supplier<java.lang.String> messageSupplier)
Asserts that
actual is not null. |
static void |
assertNotSame(java.lang.Object unexpected,
java.lang.Object actual)
Asserts that
expected and actual do not refer to the same object. |
static void |
assertNotSame(java.lang.Object unexpected,
java.lang.Object actual,
java.lang.String message)
Asserts that
expected and actual do not refer to the same object. |
static void |
assertNotSame(java.lang.Object unexpected,
java.lang.Object actual,
java.util.function.Supplier<java.lang.String> messageSupplier)
Asserts that
expected and actual do not refer to the same object. |
static void |
assertNull(java.lang.Object actual)
Asserts that
actual is null. |
static void |
assertNull(java.lang.Object actual,
java.lang.String message)
Asserts that
actual is null. |
static void |
assertNull(java.lang.Object actual,
java.util.function.Supplier<java.lang.String> messageSupplier)
Asserts that
actual is null. |
static void |
assertSame(java.lang.Object expected,
java.lang.Object actual)
Asserts that
expected and actual refer to the same object. |
static void |
assertSame(java.lang.Object expected,
java.lang.Object actual,
java.lang.String message)
Asserts that
expected and actual refer to the same object. |
static void |
assertSame(java.lang.Object expected,
java.lang.Object actual,
java.util.function.Supplier<java.lang.String> messageSupplier)
Asserts that
expected and actual refer to the same object. |
static void |
assertThrows(java.lang.Class<? extends java.lang.Throwable> expected,
Executable executable)
Asserts that executing
executable will throw an exception of type expected. |
static void |
assertTrue(boolean condition)
Asserts that
condition is true. |
static void |
assertTrue(boolean condition,
java.lang.String message)
Asserts that
condition is true. |
static void |
assertTrue(java.util.function.BooleanSupplier booleanSupplier)
Asserts that
condition supplied by booleanSupplier is true. |
static void |
assertTrue(boolean condition,
java.util.function.Supplier<java.lang.String> messageSupplier)
Asserts that
condition is true. |
static void |
assertTrue(java.util.function.BooleanSupplier booleanSupplier,
java.lang.String message)
Asserts that
condition supplied by booleanSupplier is true. |
static void |
assertTrue(java.util.function.BooleanSupplier booleanSupplier,
java.util.function.Supplier<java.lang.String> messageSupplier)
Asserts that
condition supplied by booleanSupplier is true. |
static <T extends java.lang.Throwable> |
expectThrows(java.lang.Class<T> expectedType,
Executable executable)
Asserts that executing
executable will throw an exception of type expected. |
static void |
fail(java.lang.String message)
Fails a test with a given
message. |
static void |
fail(java.util.function.Supplier<java.lang.String> messageSupplier)
Fails a test and retrieve failure message from
messageSupplier. |
public static void fail(java.lang.String message)
message.public static void fail(java.util.function.Supplier<java.lang.String> messageSupplier)
messageSupplier.public static void assertTrue(boolean condition)
condition is true.public static void assertTrue(boolean condition,
java.util.function.Supplier<java.lang.String> messageSupplier)
condition is true.
Retrieve failure message from messageSupplier.public static void assertTrue(java.util.function.BooleanSupplier booleanSupplier)
condition supplied by booleanSupplier is true.public static void assertTrue(java.util.function.BooleanSupplier booleanSupplier,
java.lang.String message)
condition supplied by booleanSupplier is true.
Fail with message message.public static void assertTrue(boolean condition,
java.lang.String message)
condition is true.
Fail with message message.public static void assertTrue(java.util.function.BooleanSupplier booleanSupplier,
java.util.function.Supplier<java.lang.String> messageSupplier)
condition supplied by booleanSupplier is true.
Retrieve failure message from messageSupplier.public static void assertFalse(boolean condition)
condition is not true.public static void assertFalse(boolean condition,
java.lang.String message)
condition is not true.
Fail with message message.public static void assertFalse(boolean condition,
java.util.function.Supplier<java.lang.String> messageSupplier)
condition is not true.
Retrieve failure message from messageSupplier.public static void assertFalse(java.util.function.BooleanSupplier booleanSupplier)
condition supplied by booleanSupplier is not true.public static void assertFalse(java.util.function.BooleanSupplier booleanSupplier,
java.lang.String message)
condition supplied by booleanSupplier is not true.
Fail with message message.public static void assertFalse(java.util.function.BooleanSupplier booleanSupplier,
java.util.function.Supplier<java.lang.String> messageSupplier)
condition supplied by booleanSupplier is not true.
Retrieve failure message from messageSupplier.public static void assertNull(java.lang.Object actual)
actual is null.public static void assertNull(java.lang.Object actual,
java.lang.String message)
actual is null.
Fail with message message.public static void assertNull(java.lang.Object actual,
java.util.function.Supplier<java.lang.String> messageSupplier)
actual is null.
Retrieve failure message from messageSupplier.public static void assertNotNull(java.lang.Object actual)
actual is not null.public static void assertNotNull(java.lang.Object actual,
java.lang.String message)
actual is not null.
Fail with message message.public static void assertNotNull(java.lang.Object actual,
java.util.function.Supplier<java.lang.String> messageSupplier)
actual is not null.
Retrieve failure message from messageSupplier.public static void assertEquals(java.lang.Object expected,
java.lang.Object actual)
expected and actual are equal. If both are null, they are considered equal.public static void assertEquals(java.lang.Object expected,
java.lang.Object actual,
java.lang.String message)
expected and actual are equal. If both are null, they are considered equal.
Fail with message message.public static void assertEquals(java.lang.Object expected,
java.lang.Object actual,
java.util.function.Supplier<java.lang.String> messageSupplier)
expected and actual are equal. If both are null, they are considered equal.
Retrieve failure message from messageSupplier.public static void assertNotEquals(java.lang.Object unexpected,
java.lang.Object actual)
expected and actual are not equal. Fail if both are null.public static void assertNotEquals(java.lang.Object unexpected,
java.lang.Object actual,
java.lang.String message)
expected and actual are not equal. Fail if both are null.
Fail with message message.public static void assertNotEquals(java.lang.Object unexpected,
java.lang.Object actual,
java.util.function.Supplier<java.lang.String> messageSupplier)
expected and actual are not equal. Fail if both are null.
Retrieve failure message from messageSupplier.public static void assertSame(java.lang.Object expected,
java.lang.Object actual)
expected and actual refer to the same object.public static void assertSame(java.lang.Object expected,
java.lang.Object actual,
java.lang.String message)
expected and actual refer to the same object.
Fail with message message.public static void assertSame(java.lang.Object expected,
java.lang.Object actual,
java.util.function.Supplier<java.lang.String> messageSupplier)
expected and actual refer to the same object.
Retrieve failure message from messageSupplier.public static void assertNotSame(java.lang.Object unexpected,
java.lang.Object actual)
expected and actual do not refer to the same object.public static void assertNotSame(java.lang.Object unexpected,
java.lang.Object actual,
java.lang.String message)
expected and actual do not refer to the same object.
Fail with message message.public static void assertNotSame(java.lang.Object unexpected,
java.lang.Object actual,
java.util.function.Supplier<java.lang.String> messageSupplier)
expected and actual do not refer to the same object.
Retrieve failure message from messageSupplier.@API(value=Experimental) public static void assertAll(Executable... asserts) throws org.opentest4j.MultipleFailuresError
asserts do not fail.
Report a failure of at least one in a MultipleFailuresError.org.opentest4j.MultipleFailuresError@API(value=Experimental)
public static void assertAll(java.lang.String heading,
Executable... asserts)
throws org.opentest4j.MultipleFailuresError
asserts do not fail.
Report a failure of at least one in a MultipleFailuresError.
Include heading in the exception's message string.
org.opentest4j.MultipleFailuresErrorpublic static void assertThrows(java.lang.Class<? extends java.lang.Throwable> expected,
Executable executable)
executable will throw an exception of type expected.
If no exception is thrown or if an exception of a different type is thrown, the method will fail.
Use assertThrows if you do not want to perform additional checks on the exception instance.
Otherwise use expectThrows(Class, Executable).
public static <T extends java.lang.Throwable> T expectThrows(java.lang.Class<T> expectedType,
Executable executable)
executable will throw an exception of type expected.
If no exception is thrown or if an exception of a different type is thrown, the method will fail.
The thrown exception instance is returned.
Use expectThrows if you want to perform additional checks on the exception instance.
Otherwise use assertThrows(Class, Executable).