@API(value=Maintained) public final class Assertions extends Object
Assertions
is a collection of utility methods that support asserting
conditions in tests.
Unless otherwise noted, a failed assertion will throw an
AssertionFailedError
or a subclass thereof.
AssertionFailedError
,
Assumptions
Modifier and Type | Method and Description |
---|---|
static void |
assertAll(Executable... executables)
Asserts that all supplied
executables do not throw an
AssertionError . |
static void |
assertAll(Stream<Executable> executables)
Asserts that all supplied
executables do not throw an
AssertionError . |
static void |
assertAll(String heading,
Executable... executables)
Asserts that all supplied
executables do not throw an
AssertionError . |
static void |
assertAll(String heading,
Stream<Executable> executables)
Asserts that all supplied
executables do not throw an
AssertionError . |
static void |
assertArrayEquals(boolean[] expected,
boolean[] actual)
Asserts that
expected and actual boolean arrays are equal. |
static void |
assertArrayEquals(boolean[] expected,
boolean[] actual,
String message)
Asserts that
expected and actual boolean arrays are equal. |
static void |
assertArrayEquals(boolean[] expected,
boolean[] actual,
Supplier<String> messageSupplier)
Asserts that
expected and actual boolean arrays are equal. |
static void |
assertArrayEquals(byte[] expected,
byte[] actual)
Asserts that
expected and actual byte arrays are equal. |
static void |
assertArrayEquals(byte[] expected,
byte[] actual,
String message)
Asserts that
expected and actual byte arrays are equal. |
static void |
assertArrayEquals(byte[] expected,
byte[] actual,
Supplier<String> messageSupplier)
Asserts that
expected and actual byte arrays are equal. |
static void |
assertArrayEquals(char[] expected,
char[] actual)
Asserts that
expected and actual char arrays are equal. |
static void |
assertArrayEquals(char[] expected,
char[] actual,
String message)
Asserts that
expected and actual char arrays are equal. |
static void |
assertArrayEquals(char[] expected,
char[] actual,
Supplier<String> messageSupplier)
Asserts that
expected and actual char arrays are equal. |
static void |
assertArrayEquals(double[] expected,
double[] actual)
Asserts that
expected and actual double arrays are equal. |
static void |
assertArrayEquals(double[] expected,
double[] actual,
double delta)
Asserts that
expected and actual double arrays are equal within the given delta . |
static void |
assertArrayEquals(double[] expected,
double[] actual,
double delta,
String message)
Asserts that
expected and actual double arrays are equal within the given delta . |
static void |
assertArrayEquals(double[] expected,
double[] actual,
double delta,
Supplier<String> messageSupplier)
Asserts that
expected and actual double arrays are equal within the given delta . |
static void |
assertArrayEquals(double[] expected,
double[] actual,
String message)
Asserts that
expected and actual double arrays are equal. |
static void |
assertArrayEquals(double[] expected,
double[] actual,
Supplier<String> messageSupplier)
Asserts that
expected and actual double arrays are equal. |
static void |
assertArrayEquals(float[] expected,
float[] actual)
Asserts that
expected and actual float arrays are equal. |
static void |
assertArrayEquals(float[] expected,
float[] actual,
float delta)
Asserts that
expected and actual float arrays are equal within the given delta . |
static void |
assertArrayEquals(float[] expected,
float[] actual,
float delta,
String message)
Asserts that
expected and actual float arrays are equal within the given delta . |
static void |
assertArrayEquals(float[] expected,
float[] actual,
float delta,
Supplier<String> messageSupplier)
Asserts that
expected and actual float arrays are equal within the given delta . |
static void |
assertArrayEquals(float[] expected,
float[] actual,
String message)
Asserts that
expected and actual float arrays are equal. |
static void |
assertArrayEquals(float[] expected,
float[] actual,
Supplier<String> messageSupplier)
Asserts that
expected and actual float arrays are equal. |
static void |
assertArrayEquals(int[] expected,
int[] actual)
Asserts that
expected and actual int arrays are equal. |
static void |
assertArrayEquals(int[] expected,
int[] actual,
String message)
Asserts that
expected and actual int arrays are equal. |
static void |
assertArrayEquals(int[] expected,
int[] actual,
Supplier<String> messageSupplier)
Asserts that
expected and actual int arrays are equal. |
static void |
assertArrayEquals(long[] expected,
long[] actual)
Asserts that
expected and actual long arrays are equal. |
static void |
assertArrayEquals(long[] expected,
long[] actual,
String message)
Asserts that
expected and actual long arrays are equal. |
static void |
assertArrayEquals(long[] expected,
long[] actual,
Supplier<String> messageSupplier)
Asserts that
expected and actual long arrays are equal. |
static void |
assertArrayEquals(Object[] expected,
Object[] actual)
Asserts that
expected and actual object arrays are deeply equal. |
static void |
assertArrayEquals(Object[] expected,
Object[] actual,
String message)
Asserts that
expected and actual object arrays are deeply equal. |
static void |
assertArrayEquals(Object[] expected,
Object[] actual,
Supplier<String> messageSupplier)
Asserts that
expected and actual object arrays are deeply equal. |
static void |
assertArrayEquals(short[] expected,
short[] actual)
Asserts that
expected and actual short arrays are equal. |
static void |
assertArrayEquals(short[] expected,
short[] actual,
String message)
Asserts that
expected and actual short arrays are equal. |
static void |
assertArrayEquals(short[] expected,
short[] actual,
Supplier<String> messageSupplier)
Asserts that
expected and actual short arrays are equal. |
static void |
assertEquals(byte expected,
byte actual)
Asserts that
expected and actual are equal. |
static void |
assertEquals(byte expected,
byte actual,
String message)
Asserts that
expected and actual are equal. |
static void |
assertEquals(byte expected,
byte actual,
Supplier<String> messageSupplier)
Asserts that
expected and actual are equal. |
static void |
assertEquals(char expected,
char actual)
Asserts that
expected and actual are equal. |
static void |
assertEquals(char expected,
char actual,
String message)
Asserts that
expected and actual are equal. |
static void |
assertEquals(char expected,
char actual,
Supplier<String> messageSupplier)
Asserts that
expected and actual are equal. |
static void |
assertEquals(double expected,
double actual)
Asserts that
expected and actual are equal. |
static void |
assertEquals(double expected,
double actual,
double delta)
Asserts that
expected and actual are equal within the given delta . |
static void |
assertEquals(double expected,
double actual,
double delta,
String message)
Asserts that
expected and actual are equal within the given delta . |
static void |
assertEquals(double expected,
double actual,
double delta,
Supplier<String> messageSupplier)
Asserts that
expected and actual are equal within the given delta . |
static void |
assertEquals(double expected,
double actual,
String message)
Asserts that
expected and actual are equal. |
static void |
assertEquals(double expected,
double actual,
Supplier<String> messageSupplier)
Asserts that
expected and actual are equal. |
static void |
assertEquals(float expected,
float actual)
Asserts that
expected and actual are equal. |
static void |
assertEquals(float expected,
float actual,
float delta)
Asserts that
expected and actual are equal within the given delta . |
static void |
assertEquals(float expected,
float actual,
float delta,
String message)
Asserts that
expected and actual are equal within the given delta . |
static void |
assertEquals(float expected,
float actual,
float delta,
Supplier<String> messageSupplier)
Asserts that
expected and actual are equal within the given delta . |
static void |
assertEquals(float expected,
float actual,
String message)
Asserts that
expected and actual are equal. |
static void |
assertEquals(float expected,
float actual,
Supplier<String> messageSupplier)
Asserts that
expected and actual are equal. |
static void |
assertEquals(int expected,
int actual)
Asserts that
expected and actual are equal. |
static void |
assertEquals(int expected,
int actual,
String message)
Asserts that
expected and actual are equal. |
static void |
assertEquals(int expected,
int actual,
Supplier<String> messageSupplier)
Asserts that
expected and actual are equal. |
static void |
assertEquals(long expected,
long actual)
Asserts that
expected and actual are equal. |
static void |
assertEquals(long expected,
long actual,
String message)
Asserts that
expected and actual are equal. |
static void |
assertEquals(long expected,
long actual,
Supplier<String> messageSupplier)
Asserts that
expected and actual are equal. |
static void |
assertEquals(Object expected,
Object actual)
Asserts that
expected and actual are equal. |
static void |
assertEquals(Object expected,
Object actual,
String message)
Asserts that
expected and actual are equal. |
static void |
assertEquals(Object expected,
Object actual,
Supplier<String> messageSupplier)
Asserts that
expected and actual are equal. |
static void |
assertEquals(short expected,
short actual)
Asserts that
expected and actual are equal. |
static void |
assertEquals(short expected,
short actual,
String message)
Asserts that
expected and actual are equal. |
static void |
assertEquals(short expected,
short actual,
Supplier<String> messageSupplier)
Asserts that
expected and actual are equal. |
static void |
assertFalse(boolean condition)
Asserts that the supplied
condition is not true . |
static void |
assertFalse(boolean condition,
String message)
Asserts that the supplied
condition is not true . |
static void |
assertFalse(BooleanSupplier booleanSupplier)
Asserts that the boolean condition supplied by
booleanSupplier is not true . |
static void |
assertFalse(boolean condition,
Supplier<String> messageSupplier)
Asserts that the supplied
condition is not true . |
static void |
assertFalse(BooleanSupplier booleanSupplier,
String message)
Asserts that the boolean condition supplied by
booleanSupplier is not true . |
static void |
assertFalse(BooleanSupplier booleanSupplier,
Supplier<String> messageSupplier)
Asserts that the boolean condition supplied by
booleanSupplier is not true . |
static void |
assertIterableEquals(Iterable<?> expected,
Iterable<?> actual)
Asserts that
expected and actual iterables are deeply equal. |
static void |
assertIterableEquals(Iterable<?> expected,
Iterable<?> actual,
String message)
Asserts that
expected and actual iterables are deeply equal. |
static void |
assertIterableEquals(Iterable<?> expected,
Iterable<?> actual,
Supplier<String> messageSupplier)
Asserts that
expected and actual iterables are deeply equal. |
static void |
assertLinesMatch(List<String> expectedLines,
List<String> actualLines)
|
static void |
assertNotEquals(Object unexpected,
Object actual)
Asserts that
expected and actual are not equal. |
static void |
assertNotEquals(Object unexpected,
Object actual,
String message)
Asserts that
expected and actual are not equal. |
static void |
assertNotEquals(Object unexpected,
Object actual,
Supplier<String> messageSupplier)
Asserts that
expected and actual are not equal. |
static void |
assertNotNull(Object actual)
Asserts that
actual is not null . |
static void |
assertNotNull(Object actual,
String message)
Asserts that
actual is not null . |
static void |
assertNotNull(Object actual,
Supplier<String> messageSupplier)
Asserts that
actual is not null . |
static void |
assertNotSame(Object unexpected,
Object actual)
Asserts that
expected and actual do not refer to the same object. |
static void |
assertNotSame(Object unexpected,
Object actual,
String message)
Asserts that
expected and actual do not refer to the same object. |
static void |
assertNotSame(Object unexpected,
Object actual,
Supplier<String> messageSupplier)
Asserts that
expected and actual do not refer to the same object. |
static void |
assertNull(Object actual)
Asserts that
actual is null . |
static void |
assertNull(Object actual,
String message)
Asserts that
actual is null . |
static void |
assertNull(Object actual,
Supplier<String> messageSupplier)
Asserts that
actual is null . |
static void |
assertSame(Object expected,
Object actual)
Asserts that
expected and actual refer to the same object. |
static void |
assertSame(Object expected,
Object actual,
String message)
Asserts that
expected and actual refer to the same object. |
static void |
assertSame(Object expected,
Object actual,
Supplier<String> messageSupplier)
Asserts that
expected and actual refer to the same object. |
static <T extends Throwable> |
assertThrows(Class<T> expectedType,
Executable executable)
Asserts that execution of the supplied
executable throws
an exception of the expectedType and returns the exception. |
static void |
assertTimeout(Duration timeout,
Executable executable)
Asserts that execution of the supplied
executable
completes before the given timeout is exceeded. |
static void |
assertTimeout(Duration timeout,
Executable executable,
String message)
Asserts that execution of the supplied
executable
completes before the given timeout is exceeded. |
static void |
assertTimeout(Duration timeout,
Executable executable,
Supplier<String> messageSupplier)
Asserts that execution of the supplied
executable
completes before the given timeout is exceeded. |
static <T> T |
assertTimeout(Duration timeout,
ThrowingSupplier<T> supplier)
Asserts that execution of the supplied
supplier
completes before the given timeout is exceeded. |
static <T> T |
assertTimeout(Duration timeout,
ThrowingSupplier<T> supplier,
String message)
Asserts that execution of the supplied
supplier
completes before the given timeout is exceeded. |
static <T> T |
assertTimeout(Duration timeout,
ThrowingSupplier<T> supplier,
Supplier<String> messageSupplier)
Asserts that execution of the supplied
supplier
completes before the given timeout is exceeded. |
static void |
assertTimeoutPreemptively(Duration timeout,
Executable executable)
Asserts that execution of the supplied
executable
completes before the given timeout is exceeded. |
static void |
assertTimeoutPreemptively(Duration timeout,
Executable executable,
String message)
Asserts that execution of the supplied
executable
completes before the given timeout is exceeded. |
static void |
assertTimeoutPreemptively(Duration timeout,
Executable executable,
Supplier<String> messageSupplier)
Asserts that execution of the supplied
executable
completes before the given timeout is exceeded. |
static <T> T |
assertTimeoutPreemptively(Duration timeout,
ThrowingSupplier<T> supplier)
Asserts that execution of the supplied
supplier
completes before the given timeout is exceeded. |
static <T> T |
assertTimeoutPreemptively(Duration timeout,
ThrowingSupplier<T> supplier,
String message)
Asserts that execution of the supplied
supplier
completes before the given timeout is exceeded. |
static <T> T |
assertTimeoutPreemptively(Duration timeout,
ThrowingSupplier<T> supplier,
Supplier<String> messageSupplier)
Asserts that execution of the supplied
supplier
completes before the given timeout is exceeded. |
static void |
assertTrue(boolean condition)
Asserts that the supplied
condition is true . |
static void |
assertTrue(boolean condition,
String message)
Asserts that the supplied
condition is true . |
static void |
assertTrue(BooleanSupplier booleanSupplier)
Asserts that the boolean condition supplied by
booleanSupplier is true . |
static void |
assertTrue(boolean condition,
Supplier<String> messageSupplier)
Asserts that the supplied
condition is true . |
static void |
assertTrue(BooleanSupplier booleanSupplier,
String message)
Asserts that the boolean condition supplied by
booleanSupplier is true . |
static void |
assertTrue(BooleanSupplier booleanSupplier,
Supplier<String> messageSupplier)
Asserts that the boolean condition supplied by
booleanSupplier is true . |
static void |
fail(String message)
Fails a test with the given failure
message . |
static void |
fail(String message,
Throwable cause)
Fails a test with the given failure
message as well
as the underlying cause . |
static void |
fail(Supplier<String> messageSupplier)
Fails a test with the failure message retrieved from the
given
messageSupplier . |
static void |
fail(Throwable cause)
Fails a test with the given underlying
cause . |
public static void fail(String message)
message
.public static void fail(String message, Throwable cause)
message
as well
as the underlying cause
.public static void fail(Throwable cause)
cause
.public static void fail(Supplier<String> messageSupplier)
messageSupplier
.public static void assertTrue(boolean condition)
condition
is true
.public static void assertTrue(boolean condition, Supplier<String> messageSupplier)
condition
is true
.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertTrue(BooleanSupplier booleanSupplier)
booleanSupplier
is true
.public static void assertTrue(BooleanSupplier booleanSupplier, String message)
booleanSupplier
is true
.
Fails with the supplied failure message
.
public static void assertTrue(boolean condition, String message)
condition
is true
.
Fails with the supplied failure message
.
public static void assertTrue(BooleanSupplier booleanSupplier, Supplier<String> messageSupplier)
booleanSupplier
is true
.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertFalse(boolean condition)
condition
is not true
.public static void assertFalse(boolean condition, String message)
condition
is not true
.
Fails with the supplied failure message
.
public static void assertFalse(boolean condition, Supplier<String> messageSupplier)
condition
is not true
.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertFalse(BooleanSupplier booleanSupplier)
booleanSupplier
is not true
.public static void assertFalse(BooleanSupplier booleanSupplier, String message)
booleanSupplier
is not true
.
Fails with the supplied failure message
.
public static void assertFalse(BooleanSupplier booleanSupplier, Supplier<String> messageSupplier)
booleanSupplier
is not true
.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertNull(Object actual)
actual
is null
.public static void assertNull(Object actual, String message)
actual
is null
.
Fails with the supplied failure message
.
public static void assertNull(Object actual, Supplier<String> messageSupplier)
actual
is null
.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertNotNull(Object actual)
actual
is not null
.public static void assertNotNull(Object actual, String message)
actual
is not null
.
Fails with the supplied failure message
.
public static void assertNotNull(Object actual, Supplier<String> messageSupplier)
actual
is not null
.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertEquals(short expected, short actual)
expected
and actual
are equal.public static void assertEquals(short expected, short actual, String message)
expected
and actual
are equal.public static void assertEquals(short expected, short actual, Supplier<String> messageSupplier)
expected
and actual
are equal.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertEquals(byte expected, byte actual)
expected
and actual
are equal.public static void assertEquals(byte expected, byte actual, String message)
expected
and actual
are equal.public static void assertEquals(byte expected, byte actual, Supplier<String> messageSupplier)
expected
and actual
are equal.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertEquals(int expected, int actual)
expected
and actual
are equal.public static void assertEquals(int expected, int actual, String message)
expected
and actual
are equal.public static void assertEquals(int expected, int actual, Supplier<String> messageSupplier)
expected
and actual
are equal.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertEquals(long expected, long actual)
expected
and actual
are equal.public static void assertEquals(long expected, long actual, String message)
expected
and actual
are equal.public static void assertEquals(long expected, long actual, Supplier<String> messageSupplier)
expected
and actual
are equal.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertEquals(char expected, char actual)
expected
and actual
are equal.public static void assertEquals(char expected, char actual, String message)
expected
and actual
are equal.public static void assertEquals(char expected, char actual, Supplier<String> messageSupplier)
expected
and actual
are equal.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertEquals(float expected, float actual)
expected
and actual
are equal.
Equality imposed by this method is consistent with Float.equals(Object)
and
Float.compare(float, float)
.
public static void assertEquals(float expected, float actual, String message)
expected
and actual
are equal.
Equality imposed by this method is consistent with Float.equals(Object)
and
Float.compare(float, float)
.
public static void assertEquals(float expected, float actual, Supplier<String> messageSupplier)
expected
and actual
are equal.
Equality imposed by this method is consistent with Float.equals(Object)
and
Float.compare(float, float)
.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertEquals(float expected, float actual, float delta)
expected
and actual
are equal within the given delta
.
Equality imposed by this method is consistent with Float.equals(Object)
and
Float.compare(float, float)
.
public static void assertEquals(float expected, float actual, float delta, String message)
expected
and actual
are equal within the given delta
.
Equality imposed by this method is consistent with Float.equals(Object)
and
Float.compare(float, float)
.
public static void assertEquals(float expected, float actual, float delta, Supplier<String> messageSupplier)
expected
and actual
are equal within the given delta
.
Equality imposed by this method is consistent with Float.equals(Object)
and
Float.compare(float, float)
.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertEquals(double expected, double actual)
expected
and actual
are equal.
Equality imposed by this method is consistent with Double.equals(Object)
and
Double.compare(double, double)
.
public static void assertEquals(double expected, double actual, String message)
expected
and actual
are equal.
Equality imposed by this method is consistent with Double.equals(Object)
and
Double.compare(double, double)
.
public static void assertEquals(double expected, double actual, Supplier<String> messageSupplier)
expected
and actual
are equal.
Equality imposed by this method is consistent with Double.equals(Object)
and
Double.compare(double, double)
.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertEquals(double expected, double actual, double delta)
expected
and actual
are equal within the given delta
.
Equality imposed by this method is consistent with Double.equals(Object)
and
Double.compare(double, double)
.
public static void assertEquals(double expected, double actual, double delta, String message)
expected
and actual
are equal within the given delta
.
Equality imposed by this method is consistent with Double.equals(Object)
and
Double.compare(double, double)
.
public static void assertEquals(double expected, double actual, double delta, Supplier<String> messageSupplier)
expected
and actual
are equal within the given delta
.
Equality imposed by this method is consistent with Double.equals(Object)
and
Double.compare(double, double)
.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertEquals(Object expected, Object actual)
expected
and actual
are equal.
If both are null
, they are considered equal.
Object.equals(Object)
public static void assertEquals(Object expected, Object actual, String message)
expected
and actual
are equal.
If both are null
, they are considered equal.
Fails with the supplied failure message
.
Object.equals(Object)
public static void assertEquals(Object expected, Object actual, Supplier<String> messageSupplier)
expected
and actual
are equal.
If both are null
, they are considered equal.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
Object.equals(Object)
public static void assertArrayEquals(boolean[] expected, boolean[] actual)
expected
and actual
boolean arrays are equal.
If both are null
, they are considered equal.
public static void assertArrayEquals(boolean[] expected, boolean[] actual, String message)
expected
and actual
boolean arrays are equal.
If both are null
, they are considered equal.
Fails with the supplied failure message
.
public static void assertArrayEquals(boolean[] expected, boolean[] actual, Supplier<String> messageSupplier)
expected
and actual
boolean arrays are equal.
If both are null
, they are considered equal.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertArrayEquals(char[] expected, char[] actual)
expected
and actual
char arrays are equal.
If both are null
, they are considered equal.
public static void assertArrayEquals(char[] expected, char[] actual, String message)
expected
and actual
char arrays are equal.
If both are null
, they are considered equal.
Fails with the supplied failure message
.
public static void assertArrayEquals(char[] expected, char[] actual, Supplier<String> messageSupplier)
expected
and actual
char arrays are equal.
If both are null
, they are considered equal.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertArrayEquals(byte[] expected, byte[] actual)
expected
and actual
byte arrays are equal.
If both are null
, they are considered equal.
public static void assertArrayEquals(byte[] expected, byte[] actual, String message)
expected
and actual
byte arrays are equal.
If both are null
, they are considered equal.
Fails with the supplied failure message
.
public static void assertArrayEquals(byte[] expected, byte[] actual, Supplier<String> messageSupplier)
expected
and actual
byte arrays are equal.
If both are null
, they are considered equal.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertArrayEquals(short[] expected, short[] actual)
expected
and actual
short arrays are equal.
If both are null
, they are considered equal.
public static void assertArrayEquals(short[] expected, short[] actual, String message)
expected
and actual
short arrays are equal.
If both are null
, they are considered equal.
Fails with the supplied failure message
.
public static void assertArrayEquals(short[] expected, short[] actual, Supplier<String> messageSupplier)
expected
and actual
short arrays are equal.
If both are null
, they are considered equal.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertArrayEquals(int[] expected, int[] actual)
expected
and actual
int arrays are equal.
If both are null
, they are considered equal.
public static void assertArrayEquals(int[] expected, int[] actual, String message)
expected
and actual
int arrays are equal.
If both are null
, they are considered equal.
Fails with the supplied failure message
.
public static void assertArrayEquals(int[] expected, int[] actual, Supplier<String> messageSupplier)
expected
and actual
int arrays are equal.
If both are null
, they are considered equal.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertArrayEquals(long[] expected, long[] actual)
expected
and actual
long arrays are equal.
If both are null
, they are considered equal.
public static void assertArrayEquals(long[] expected, long[] actual, String message)
expected
and actual
long arrays are equal.
If both are null
, they are considered equal.
Fails with the supplied failure message
.
public static void assertArrayEquals(long[] expected, long[] actual, Supplier<String> messageSupplier)
expected
and actual
long arrays are equal.
If both are null
, they are considered equal.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertArrayEquals(float[] expected, float[] actual)
expected
and actual
float arrays are equal.
Equality imposed by this method is consistent with Float.equals(Object)
and
Float.compare(float, float)
.
public static void assertArrayEquals(float[] expected, float[] actual, String message)
expected
and actual
float arrays are equal.
Equality imposed by this method is consistent with Float.equals(Object)
and
Float.compare(float, float)
.
Fails with the supplied failure message
.
public static void assertArrayEquals(float[] expected, float[] actual, Supplier<String> messageSupplier)
expected
and actual
float arrays are equal.
Equality imposed by this method is consistent with Float.equals(Object)
and
Float.compare(float, float)
.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertArrayEquals(float[] expected, float[] actual, float delta)
expected
and actual
float arrays are equal within the given delta
.
Equality imposed by this method is consistent with Float.equals(Object)
and
Float.compare(float, float)
.
public static void assertArrayEquals(float[] expected, float[] actual, float delta, String message)
expected
and actual
float arrays are equal within the given delta
.
Equality imposed by this method is consistent with Float.equals(Object)
and
Float.compare(float, float)
.
Fails with the supplied failure message
.
public static void assertArrayEquals(float[] expected, float[] actual, float delta, Supplier<String> messageSupplier)
expected
and actual
float arrays are equal within the given delta
.
Equality imposed by this method is consistent with Float.equals(Object)
and
Float.compare(float, float)
.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertArrayEquals(double[] expected, double[] actual)
expected
and actual
double arrays are equal.
Equality imposed by this method is consistent with Double.equals(Object)
and
Double.compare(double, double)
.
public static void assertArrayEquals(double[] expected, double[] actual, String message)
expected
and actual
double arrays are equal.
Equality imposed by this method is consistent with Double.equals(Object)
and
Double.compare(double, double)
.
Fails with the supplied failure message
.
public static void assertArrayEquals(double[] expected, double[] actual, Supplier<String> messageSupplier)
expected
and actual
double arrays are equal.
Equality imposed by this method is consistent with Double.equals(Object)
and
Double.compare(double, double)
.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertArrayEquals(double[] expected, double[] actual, double delta)
expected
and actual
double arrays are equal within the given delta
.
Equality imposed by this method is consistent with Double.equals(Object)
and
Double.compare(double, double)
.
public static void assertArrayEquals(double[] expected, double[] actual, double delta, String message)
expected
and actual
double arrays are equal within the given delta
.
Equality imposed by this method is consistent with Double.equals(Object)
and
Double.compare(double, double)
.
Fails with the supplied failure message
.
public static void assertArrayEquals(double[] expected, double[] actual, double delta, Supplier<String> messageSupplier)
expected
and actual
double arrays are equal within the given delta
.
Equality imposed by this method is consistent with Double.equals(Object)
and
Double.compare(double, double)
.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertArrayEquals(Object[] expected, Object[] actual)
expected
and actual
object arrays are deeply equal.
If both are null
, they are considered equal.
Nested float arrays are checked as in assertEquals(float, float)
.
Nested double arrays are checked as in assertEquals(double, double)
.
public static void assertArrayEquals(Object[] expected, Object[] actual, String message)
expected
and actual
object arrays are deeply equal.
If both are null
, they are considered equal.
Nested float arrays are checked as in assertEquals(float, float)
.
Nested double arrays are checked as in assertEquals(double, double)
.
Fails with the supplied failure message
.
public static void assertArrayEquals(Object[] expected, Object[] actual, Supplier<String> messageSupplier)
expected
and actual
object arrays are deeply equal.
If both are null
, they are considered equal.
Nested float arrays are checked as in assertEquals(float, float)
.
Nested double arrays are checked as in assertEquals(double, double)
.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertIterableEquals(Iterable<?> expected, Iterable<?> actual)
expected
and actual
iterables are deeply equal.
Similarly to the check for deep equality in assertArrayEquals(Object[], Object[])
,
if two iterables are encountered (including expected
and actual
) then their
iterators must return equal elements in the same order as each other. Note:
this means that the iterables do not need to be of the same type. Example:
import static java.util.Arrays.asList;
. . .
Iterable<Integer> i0 = new ArrayList<>(asList(1, 2, 3));
Iterable<Integer> i1 = new LinkedList<>(asList(1, 2, 3));
assertIterableEquals(i0, i1); // Passes
If both expected
and actual
are null
, they are considered equal.
public static void assertIterableEquals(Iterable<?> expected, Iterable<?> actual, String message)
expected
and actual
iterables are deeply equal.
Similarly to the check for deep equality in
assertArrayEquals(Object[], Object[], String)
, if two iterables are encountered
(including expected
and actual
) then their iterators must return equal
elements in the same order as each other. Note: this means that the iterables
do not need to be of the same type. Example:
import static java.util.Arrays.asList;
. . .
Iterable<Integer> i0 = new ArrayList<>(asList(1, 2, 3));
Iterable<Integer> i1 = new LinkedList<>(asList(1, 2, 3));
assertIterableEquals(i0, i1); // Passes
If both expected
and actual
are null
, they are considered equal.
Fails with the supplied failure message
.
public static void assertIterableEquals(Iterable<?> expected, Iterable<?> actual, Supplier<String> messageSupplier)
expected
and actual
iterables are deeply equal.
Similarly to the check for deep equality in
assertArrayEquals(Object[], Object[], Supplier)
, if two iterables are encountered
(including expected
and actual
) then their iterators must return equal
elements in the same order as each other. Note: this means that the iterables
do not need to be of the same type. Example:
import static java.util.Arrays.asList;
. . .
Iterable<Integer> i0 = new ArrayList<>(asList(1, 2, 3));
Iterable<Integer> i1 = new LinkedList<>(asList(1, 2, 3));
assertIterableEquals(i0, i1); // Passes
If both expected
and actual
are null
, they are considered equal.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertLinesMatch(List<String> expectedLines, List<String> actualLines)
expected
list of Strings matches actual
list.
This method differs from other assertions that effectively only check String.equals(Object)
,
in that it uses the following staged matching algorithm:
For each pair of expected and actual lines do
expected.equals(actual)
- if yes, continue with next pairexpected
as a regular expression and check via
String.matches(String)
- if yes, continue with next pairexpected
line is a fast-forward marker, if yes apply
fast-forward actual lines accordingly (see below) and goto 1.A valid fast-forward marker is an expected line that starts and ends with the literal
>>
and contains at least 4 characters. Examples:
>>>>
>> stacktrace >>
>> single line, non Integer.parse()-able comment >>
">> 21 >>"
Example showing all three kinds of expected line formats:
│ │ │ caught: AssertionFailedError: single line fail message
>> S T A C K T R A C E >>
│ │ │ duration: [\d]+ ms
│ │ │ status: ✘ FAILED
│ └─ test() finished after [\d]+ ms\.
└─ JUnit Jupiter finished after [\d]+ ms\.
Test plan execution finished. Number of all tests: 1
Test run finished after [\d]+ ms
public static void assertNotEquals(Object unexpected, Object actual)
expected
and actual
are not equal.
Fails if both are null
.
Object.equals(Object)
public static void assertNotEquals(Object unexpected, Object actual, String message)
expected
and actual
are not equal.
Fails if both are null
.
Fails with the supplied failure message
.
Object.equals(Object)
public static void assertNotEquals(Object unexpected, Object actual, Supplier<String> messageSupplier)
expected
and actual
are not equal.
Fails if both are null
.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
Object.equals(Object)
public static void assertSame(Object expected, Object actual)
expected
and actual
refer to the same object.public static void assertSame(Object expected, Object actual, String message)
expected
and actual
refer to the same object.
Fails with the supplied failure message
.
public static void assertSame(Object expected, Object actual, Supplier<String> messageSupplier)
expected
and actual
refer to the same object.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
public static void assertNotSame(Object unexpected, Object actual)
expected
and actual
do not refer to the same object.public static void assertNotSame(Object unexpected, Object actual, String message)
expected
and actual
do not refer to the same object.
Fails with the supplied failure message
.
public static void assertNotSame(Object unexpected, Object actual, Supplier<String> messageSupplier)
expected
and actual
do not refer to the same object.
If necessary, the failure message will be retrieved lazily from the supplied messageSupplier
.
@API(value=Experimental) public static void assertAll(Executable... executables) throws MultipleFailuresError
executables
do not throw an
AssertionError
.
See Javadoc for assertAll(String, Stream)
for an explanation of this
method's exception handling semantics.
@API(value=Experimental) public static void assertAll(Stream<Executable> executables) throws MultipleFailuresError
executables
do not throw an
AssertionError
.
See Javadoc for assertAll(String, Stream)
for an explanation of this
method's exception handling semantics.
@API(value=Experimental) public static void assertAll(String heading, Executable... executables) throws MultipleFailuresError
executables
do not throw an
AssertionError
.
See Javadoc for assertAll(String, Stream)
for an explanation of this
method's exception handling semantics.
MultipleFailuresError
assertAll(Executable...)
,
assertAll(Stream)
,
assertAll(String, Stream)
@API(value=Experimental) public static void assertAll(String heading, Stream<Executable> executables) throws MultipleFailuresError
executables
do not throw an
AssertionError
.
If any supplied Executable
throws an AssertionError
, all remaining
executables
will still be executed, and all failures will be aggregated
and reported in a MultipleFailuresError
. However, if an executable
throws an exception that is not an AssertionError
, execution will halt
immediately, and the exception will be rethrown as is but
masked
as an unchecked exception.
The supplied heading
will be included in the message string for the
MultipleFailuresError
.
public static <T extends Throwable> T assertThrows(Class<T> expectedType, Executable executable)
executable
throws
an exception of the expectedType
and returns the exception.
If no exception is thrown, or if an exception of a different type is thrown, this method will fail.
If you do not want to perform additional checks on the exception instance, simply ignore the return value.
public static void assertTimeout(Duration timeout, Executable executable)
executable
completes before the given timeout
is exceeded.
Note: the executable
will be executed in the same thread as that
of the calling code. Consequently, execution of the executable
will
not be preemptively aborted if the timeout is exceeded.
public static void assertTimeout(Duration timeout, Executable executable, String message)
executable
completes before the given timeout
is exceeded.
Note: the executable
will be executed in the same thread as that
of the calling code. Consequently, execution of the executable
will
not be preemptively aborted if the timeout is exceeded.
Fails with the supplied failure message
.
public static void assertTimeout(Duration timeout, Executable executable, Supplier<String> messageSupplier)
executable
completes before the given timeout
is exceeded.
Note: the executable
will be executed in the same thread as that
of the calling code. Consequently, execution of the executable
will
not be preemptively aborted if the timeout is exceeded.
If necessary, the failure message will be retrieved lazily from the
supplied messageSupplier
.
public static <T> T assertTimeout(Duration timeout, ThrowingSupplier<T> supplier)
supplier
completes before the given timeout
is exceeded.
If the assertion passes then the supplier
's result is returned.
Note: the supplier
will be executed in the same thread as that
of the calling code. Consequently, execution of the supplier
will
not be preemptively aborted if the timeout is exceeded.
public static <T> T assertTimeout(Duration timeout, ThrowingSupplier<T> supplier, String message)
supplier
completes before the given timeout
is exceeded.
If the assertion passes then the supplier
's result is returned.
Note: the supplier
will be executed in the same thread as that
of the calling code. Consequently, execution of the supplier
will
not be preemptively aborted if the timeout is exceeded.
Fails with the supplied failure message
.
public static <T> T assertTimeout(Duration timeout, ThrowingSupplier<T> supplier, Supplier<String> messageSupplier)
supplier
completes before the given timeout
is exceeded.
If the assertion passes then the supplier
's result is returned.
Note: the supplier
will be executed in the same thread as that
of the calling code. Consequently, execution of the supplier
will
not be preemptively aborted if the timeout is exceeded.
If necessary, the failure message will be retrieved lazily from the
supplied messageSupplier
.
public static void assertTimeoutPreemptively(Duration timeout, Executable executable)
executable
completes before the given timeout
is exceeded.
Note: the executable
will be executed in a different thread than
that of the calling code. Furthermore, execution of the executable
will
be preemptively aborted if the timeout is exceeded.
assertTimeoutPreemptively(Duration, Executable, String)
,
assertTimeoutPreemptively(Duration, Executable, Supplier)
,
assertTimeoutPreemptively(Duration, ThrowingSupplier)
,
assertTimeoutPreemptively(Duration, ThrowingSupplier, String)
,
assertTimeoutPreemptively(Duration, ThrowingSupplier, Supplier)
,
assertTimeout(Duration, Executable)
public static void assertTimeoutPreemptively(Duration timeout, Executable executable, String message)
executable
completes before the given timeout
is exceeded.
Note: the executable
will be executed in a different thread than
that of the calling code. Furthermore, execution of the executable
will
be preemptively aborted if the timeout is exceeded.
Fails with the supplied failure message
.
assertTimeoutPreemptively(Duration, Executable)
,
assertTimeoutPreemptively(Duration, Executable, Supplier)
,
assertTimeoutPreemptively(Duration, ThrowingSupplier)
,
assertTimeoutPreemptively(Duration, ThrowingSupplier, String)
,
assertTimeoutPreemptively(Duration, ThrowingSupplier, Supplier)
,
assertTimeout(Duration, Executable, String)
public static void assertTimeoutPreemptively(Duration timeout, Executable executable, Supplier<String> messageSupplier)
executable
completes before the given timeout
is exceeded.
Note: the executable
will be executed in a different thread than
that of the calling code. Furthermore, execution of the executable
will
be preemptively aborted if the timeout is exceeded.
If necessary, the failure message will be retrieved lazily from the
supplied messageSupplier
.
assertTimeoutPreemptively(Duration, Executable)
,
assertTimeoutPreemptively(Duration, Executable, String)
,
assertTimeoutPreemptively(Duration, ThrowingSupplier)
,
assertTimeoutPreemptively(Duration, ThrowingSupplier, String)
,
assertTimeoutPreemptively(Duration, ThrowingSupplier, Supplier)
,
assertTimeout(Duration, Executable, Supplier)
public static <T> T assertTimeoutPreemptively(Duration timeout, ThrowingSupplier<T> supplier)
supplier
completes before the given timeout
is exceeded.
If the assertion passes then the supplier
's result is returned.
Note: the supplier
will be executed in a different thread than
that of the calling code. Furthermore, execution of the supplier
will
be preemptively aborted if the timeout is exceeded.
assertTimeoutPreemptively(Duration, Executable)
,
assertTimeoutPreemptively(Duration, Executable, String)
,
assertTimeoutPreemptively(Duration, Executable, Supplier)
,
assertTimeoutPreemptively(Duration, ThrowingSupplier, String)
,
assertTimeoutPreemptively(Duration, ThrowingSupplier, Supplier)
,
assertTimeout(Duration, Executable)
public static <T> T assertTimeoutPreemptively(Duration timeout, ThrowingSupplier<T> supplier, String message)
supplier
completes before the given timeout
is exceeded.
If the assertion passes then the supplier
's result is returned.
Note: the supplier
will be executed in a different thread than
that of the calling code. Furthermore, execution of the supplier
will
be preemptively aborted if the timeout is exceeded.
Fails with the supplied failure message
.
assertTimeoutPreemptively(Duration, Executable)
,
assertTimeoutPreemptively(Duration, Executable, String)
,
assertTimeoutPreemptively(Duration, Executable, Supplier)
,
assertTimeoutPreemptively(Duration, ThrowingSupplier)
,
assertTimeoutPreemptively(Duration, ThrowingSupplier, Supplier)
,
assertTimeout(Duration, Executable, String)
public static <T> T assertTimeoutPreemptively(Duration timeout, ThrowingSupplier<T> supplier, Supplier<String> messageSupplier)
supplier
completes before the given timeout
is exceeded.
If the assertion passes then the supplier
's result is returned.
Note: the supplier
will be executed in a different thread than
that of the calling code. Furthermore, execution of the supplier
will
be preemptively aborted if the timeout is exceeded.
If necessary, the failure message will be retrieved lazily from the
supplied messageSupplier
.
assertTimeoutPreemptively(Duration, Executable)
,
assertTimeoutPreemptively(Duration, Executable, String)
,
assertTimeoutPreemptively(Duration, Executable, Supplier)
,
assertTimeoutPreemptively(Duration, ThrowingSupplier)
,
assertTimeoutPreemptively(Duration, ThrowingSupplier, String)
,
assertTimeout(Duration, Executable, Supplier)