org.junit.jupiter.api.Assertions Maven / Gradle / Ivy
Show all versions of junit-jupiter-api Show documentation
/*
* Copyright 2015-2016 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.junit.jupiter.api;
import static org.junit.platform.commons.meta.API.Usage.Experimental;
import static org.junit.platform.commons.meta.API.Usage.Maintained;
import java.time.Duration;
import java.util.Arrays;
import java.util.Objects;
import java.util.function.BooleanSupplier;
import java.util.function.Supplier;
import java.util.stream.Stream;
import org.junit.jupiter.api.function.Executable;
import org.junit.platform.commons.meta.API;
import org.junit.platform.commons.util.ExceptionUtils;
import org.opentest4j.MultipleFailuresError;
/**
* {@code Assertions} is a collection of utility methods that support asserting
* conditions in tests.
*
* Unless otherwise noted, a failed assertion will throw an
* {@link org.opentest4j.AssertionFailedError} or a subclass thereof.
*
* @since 5.0
* @see org.opentest4j.AssertionFailedError
* @see Assumptions
*/
@API(Maintained)
public final class Assertions {
///CLOVER:OFF
private Assertions() {
/* no-op */
}
///CLOVER:ON
// --- fail ----------------------------------------------------------------
/**
* Fails a test with the given failure {@code message}.
*/
public static void fail(String message) {
AssertionUtils.fail(message);
}
/**
* Fails a test with the failure message retrieved from the
* given {@code messageSupplier}.
*/
public static void fail(Supplier messageSupplier) {
AssertionUtils.fail(messageSupplier);
}
// --- assertTrue ----------------------------------------------------------
/**
* Asserts that the supplied {@code condition} is {@code true}.
*/
public static void assertTrue(boolean condition) {
AssertTrue.assertTrue(condition);
}
/**
* Asserts that the supplied {@code condition} is {@code true}.
* If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertTrue(boolean condition, Supplier messageSupplier) {
AssertTrue.assertTrue(condition, messageSupplier);
}
/**
* Asserts that the boolean condition supplied by {@code booleanSupplier} is {@code true}.
*/
public static void assertTrue(BooleanSupplier booleanSupplier) {
AssertTrue.assertTrue(booleanSupplier);
}
/**
* Asserts that the boolean condition supplied by {@code booleanSupplier} is {@code true}.
* Fails with the supplied failure {@code message}.
*/
public static void assertTrue(BooleanSupplier booleanSupplier, String message) {
AssertTrue.assertTrue(booleanSupplier, message);
}
/**
* Asserts that the supplied {@code condition} is {@code true}.
*
Fails with the supplied failure {@code message}.
*/
public static void assertTrue(boolean condition, String message) {
AssertTrue.assertTrue(condition, message);
}
/**
* Asserts that the boolean condition supplied by {@code booleanSupplier} is {@code true}.
*
If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertTrue(BooleanSupplier booleanSupplier, Supplier messageSupplier) {
AssertTrue.assertTrue(booleanSupplier, messageSupplier);
}
// --- assertFalse ---------------------------------------------------------
/**
* Asserts that the supplied {@code condition} is not {@code true}.
*/
public static void assertFalse(boolean condition) {
AssertFalse.assertFalse(condition);
}
/**
* Asserts that the supplied {@code condition} is not {@code true}.
* Fails with the supplied failure {@code message}.
*/
public static void assertFalse(boolean condition, String message) {
AssertFalse.assertFalse(condition, message);
}
/**
* Asserts that the supplied {@code condition} is not {@code true}.
*
If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertFalse(boolean condition, Supplier messageSupplier) {
AssertFalse.assertFalse(condition, messageSupplier);
}
/**
* Asserts that the boolean condition supplied by {@code booleanSupplier} is not {@code true}.
*/
public static void assertFalse(BooleanSupplier booleanSupplier) {
AssertFalse.assertFalse(booleanSupplier);
}
/**
* Asserts that the boolean condition supplied by {@code booleanSupplier} is not {@code true}.
* Fails with the supplied failure {@code message}.
*/
public static void assertFalse(BooleanSupplier booleanSupplier, String message) {
AssertFalse.assertFalse(booleanSupplier, message);
}
/**
* Asserts that the boolean condition supplied by {@code booleanSupplier} is not {@code true}.
*
If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertFalse(BooleanSupplier booleanSupplier, Supplier messageSupplier) {
AssertFalse.assertFalse(booleanSupplier, messageSupplier);
}
// --- assertNull ----------------------------------------------------------
/**
* Asserts that {@code actual} is {@code null}.
*/
public static void assertNull(Object actual) {
AssertNull.assertNull(actual);
}
/**
* Asserts that {@code actual} is {@code null}.
* Fails with the supplied failure {@code message}.
*/
public static void assertNull(Object actual, String message) {
AssertNull.assertNull(actual, message);
}
/**
* Asserts that {@code actual} is {@code null}.
*
If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertNull(Object actual, Supplier messageSupplier) {
AssertNull.assertNull(actual, messageSupplier);
}
// --- assertNotNull -------------------------------------------------------
/**
* Asserts that {@code actual} is not {@code null}.
*/
public static void assertNotNull(Object actual) {
AssertNotNull.assertNotNull(actual);
}
/**
* Asserts that {@code actual} is not {@code null}.
* Fails with the supplied failure {@code message}.
*/
public static void assertNotNull(Object actual, String message) {
AssertNotNull.assertNotNull(actual, message);
}
/**
* Asserts that {@code actual} is not {@code null}.
*
If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertNotNull(Object actual, Supplier messageSupplier) {
AssertNotNull.assertNotNull(actual, messageSupplier);
}
// --- assertEquals --------------------------------------------------------
/**
* Asserts that {@code expected} and {@code actual} are equal.
*/
public static void assertEquals(short expected, short actual) {
AssertEquals.assertEquals(expected, actual);
}
/**
* Asserts that {@code expected} and {@code actual} are equal.
*/
public static void assertEquals(short expected, short actual, String message) {
AssertEquals.assertEquals(expected, actual, message);
}
/**
* Asserts that {@code expected} and {@code actual} are equal.
* If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertEquals(short expected, short actual, Supplier messageSupplier) {
AssertEquals.assertEquals(expected, actual, messageSupplier);
}
/**
* Asserts that {@code expected} and {@code actual} are equal.
*/
public static void assertEquals(byte expected, byte actual) {
AssertEquals.assertEquals(expected, actual);
}
/**
* Asserts that {@code expected} and {@code actual} are equal.
*/
public static void assertEquals(byte expected, byte actual, String message) {
AssertEquals.assertEquals(expected, actual, message);
}
/**
* Asserts that {@code expected} and {@code actual} are equal.
* If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertEquals(byte expected, byte actual, Supplier messageSupplier) {
AssertEquals.assertEquals(expected, actual, messageSupplier);
}
/**
* Asserts that {@code expected} and {@code actual} are equal.
*/
public static void assertEquals(int expected, int actual) {
AssertEquals.assertEquals(expected, actual);
}
/**
* Asserts that {@code expected} and {@code actual} are equal.
*/
public static void assertEquals(int expected, int actual, String message) {
AssertEquals.assertEquals(expected, actual, message);
}
/**
* Asserts that {@code expected} and {@code actual} are equal.
* If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertEquals(int expected, int actual, Supplier messageSupplier) {
AssertEquals.assertEquals(expected, actual, messageSupplier);
}
/**
* Asserts that {@code expected} and {@code actual} are equal.
*/
public static void assertEquals(long expected, long actual) {
AssertEquals.assertEquals(expected, actual);
}
/**
* Asserts that {@code expected} and {@code actual} are equal.
*/
public static void assertEquals(long expected, long actual, String message) {
AssertEquals.assertEquals(expected, actual, message);
}
/**
* Asserts that {@code expected} and {@code actual} are equal.
* If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertEquals(long expected, long actual, Supplier messageSupplier) {
AssertEquals.assertEquals(expected, actual, messageSupplier);
}
/**
* Asserts that {@code expected} and {@code actual} are equal.
*/
public static void assertEquals(char expected, char actual) {
AssertEquals.assertEquals(expected, actual);
}
/**
* Asserts that {@code expected} and {@code actual} are equal.
*/
public static void assertEquals(char expected, char actual, String message) {
AssertEquals.assertEquals(expected, actual, message);
}
/**
* Asserts that {@code expected} and {@code actual} are equal.
* If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertEquals(char expected, char actual, Supplier messageSupplier) {
AssertEquals.assertEquals(expected, actual, messageSupplier);
}
/**
* Asserts that {@code expected} and {@code actual} are equal.
* Equality imposed by this method is consistent with {@link Float#equals(Object)} and
* {@link Float#compare(float, float)}.
*/
public static void assertEquals(float expected, float actual) {
AssertEquals.assertEquals(expected, actual);
}
/**
* Asserts that {@code expected} and {@code actual} are equal.
* Equality imposed by this method is consistent with {@link Float#equals(Object)} and
* {@link Float#compare(float, float)}.
*/
public static void assertEquals(float expected, float actual, String message) {
AssertEquals.assertEquals(expected, actual, message);
}
/**
* Asserts that {@code expected} and {@code actual} are equal.
* Equality imposed by this method is consistent with {@link Float#equals(Object)} and
* {@link Float#compare(float, float)}.
* If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertEquals(float expected, float actual, Supplier messageSupplier) {
AssertEquals.assertEquals(expected, actual, messageSupplier);
}
/**
* Asserts that {@code expected} and {@code actual} are equal within the given {@code delta}.
* Equality imposed by this method is consistent with {@link Float#equals(Object)} and
* {@link Float#compare(float, float)}.
*/
public static void assertEquals(float expected, float actual, float delta) {
AssertEquals.assertEquals(expected, actual, delta);
}
/**
* Asserts that {@code expected} and {@code actual} are equal within the given {@code delta}.
* Equality imposed by this method is consistent with {@link Float#equals(Object)} and
* {@link Float#compare(float, float)}.
*/
public static void assertEquals(float expected, float actual, float delta, String message) {
AssertEquals.assertEquals(expected, actual, delta, message);
}
/**
* Asserts that {@code expected} and {@code actual} are equal within the given {@code delta}.
* Equality imposed by this method is consistent with {@link Float#equals(Object)} and
* {@link Float#compare(float, float)}.
* If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertEquals(float expected, float actual, float delta, Supplier messageSupplier) {
AssertEquals.assertEquals(expected, actual, delta, messageSupplier);
}
/**
* Asserts that {@code expected} and {@code actual} are equal.
* Equality imposed by this method is consistent with {@link Double#equals(Object)} and
* {@link Double#compare(double, double)}.
*/
public static void assertEquals(double expected, double actual) {
AssertEquals.assertEquals(expected, actual);
}
/**
* Asserts that {@code expected} and {@code actual} are equal.
* Equality imposed by this method is consistent with {@link Double#equals(Object)} and
* {@link Double#compare(double, double)}.
*/
public static void assertEquals(double expected, double actual, String message) {
AssertEquals.assertEquals(expected, actual, message);
}
/**
* Asserts that {@code expected} and {@code actual} are equal.
* Equality imposed by this method is consistent with {@link Double#equals(Object)} and
* {@link Double#compare(double, double)}.
* If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertEquals(double expected, double actual, Supplier messageSupplier) {
AssertEquals.assertEquals(expected, actual, messageSupplier);
}
/**
* Asserts that {@code expected} and {@code actual} are equal within the given {@code delta}.
* Equality imposed by this method is consistent with {@link Double#equals(Object)} and
* {@link Double#compare(double, double)}.
*/
public static void assertEquals(double expected, double actual, double delta) {
AssertEquals.assertEquals(expected, actual, delta);
}
/**
* Asserts that {@code expected} and {@code actual} are equal within the given {@code delta}.
* Equality imposed by this method is consistent with {@link Double#equals(Object)} and
* {@link Double#compare(double, double)}.
*/
public static void assertEquals(double expected, double actual, double delta, String message) {
AssertEquals.assertEquals(expected, actual, delta, message);
}
/**
* Asserts that {@code expected} and {@code actual} are equal within the given {@code delta}.
* Equality imposed by this method is consistent with {@link Double#equals(Object)} and
* {@link Double#compare(double, double)}.
* If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertEquals(double expected, double actual, double delta, Supplier messageSupplier) {
AssertEquals.assertEquals(expected, actual, delta, messageSupplier);
}
/**
* Asserts that {@code expected} and {@code actual} are equal.
* If both are {@code null}, they are considered equal.
*
* @see Object#equals(Object)
*/
public static void assertEquals(Object expected, Object actual) {
AssertEquals.assertEquals(expected, actual);
}
/**
* Asserts that {@code expected} and {@code actual} are equal.
*
If both are {@code null}, they are considered equal.
*
Fails with the supplied failure {@code message}.
*
* @see Object#equals(Object)
*/
public static void assertEquals(Object expected, Object actual, String message) {
AssertEquals.assertEquals(expected, actual, message);
}
/**
* Asserts that {@code expected} and {@code actual} are equal.
*
If both are {@code null}, they are considered equal.
*
If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*
* @see Object#equals(Object)
*/
public static void assertEquals(Object expected, Object actual, Supplier messageSupplier) {
AssertEquals.assertEquals(expected, actual, messageSupplier);
}
// --- assertArrayEquals ---------------------------------------------------
/**
* Asserts that {@code expected} and {@code actual} boolean arrays are equal.
* If both are {@code null}, they are considered equal.
*/
public static void assertArrayEquals(boolean[] expected, boolean[] actual) {
AssertArrayEquals.assertArrayEquals(expected, actual);
}
/**
* Asserts that {@code expected} and {@code actual} boolean arrays are equal.
*
If both are {@code null}, they are considered equal.
*
Fails with the supplied failure {@code message}.
*/
public static void assertArrayEquals(boolean[] expected, boolean[] actual, String message) {
AssertArrayEquals.assertArrayEquals(expected, actual, message);
}
/**
* Asserts that {@code expected} and {@code actual} boolean arrays are equal.
*
If both are {@code null}, they are considered equal.
*
If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertArrayEquals(boolean[] expected, boolean[] actual, Supplier messageSupplier) {
AssertArrayEquals.assertArrayEquals(expected, actual, messageSupplier);
}
/**
* Asserts that {@code expected} and {@code actual} char arrays are equal.
* If both are {@code null}, they are considered equal.
*/
public static void assertArrayEquals(char[] expected, char[] actual) {
AssertArrayEquals.assertArrayEquals(expected, actual);
}
/**
* Asserts that {@code expected} and {@code actual} char arrays are equal.
*
If both are {@code null}, they are considered equal.
*
Fails with the supplied failure {@code message}.
*/
public static void assertArrayEquals(char[] expected, char[] actual, String message) {
AssertArrayEquals.assertArrayEquals(expected, actual, message);
}
/**
* Asserts that {@code expected} and {@code actual} char arrays are equal.
*
If both are {@code null}, they are considered equal.
*
If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertArrayEquals(char[] expected, char[] actual, Supplier messageSupplier) {
AssertArrayEquals.assertArrayEquals(expected, actual, messageSupplier);
}
/**
* Asserts that {@code expected} and {@code actual} byte arrays are equal.
* If both are {@code null}, they are considered equal.
*/
public static void assertArrayEquals(byte[] expected, byte[] actual) {
AssertArrayEquals.assertArrayEquals(expected, actual);
}
/**
* Asserts that {@code expected} and {@code actual} byte arrays are equal.
*
If both are {@code null}, they are considered equal.
*
Fails with the supplied failure {@code message}.
*/
public static void assertArrayEquals(byte[] expected, byte[] actual, String message) {
AssertArrayEquals.assertArrayEquals(expected, actual, message);
}
/**
* Asserts that {@code expected} and {@code actual} byte arrays are equal.
*
If both are {@code null}, they are considered equal.
*
If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertArrayEquals(byte[] expected, byte[] actual, Supplier messageSupplier) {
AssertArrayEquals.assertArrayEquals(expected, actual, messageSupplier);
}
/**
* Asserts that {@code expected} and {@code actual} short arrays are equal.
* If both are {@code null}, they are considered equal.
*/
public static void assertArrayEquals(short[] expected, short[] actual) {
AssertArrayEquals.assertArrayEquals(expected, actual);
}
/**
* Asserts that {@code expected} and {@code actual} short arrays are equal.
*
If both are {@code null}, they are considered equal.
*
Fails with the supplied failure {@code message}.
*/
public static void assertArrayEquals(short[] expected, short[] actual, String message) {
AssertArrayEquals.assertArrayEquals(expected, actual, message);
}
/**
* Asserts that {@code expected} and {@code actual} short arrays are equal.
*
If both are {@code null}, they are considered equal.
*
If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertArrayEquals(short[] expected, short[] actual, Supplier messageSupplier) {
AssertArrayEquals.assertArrayEquals(expected, actual, messageSupplier);
}
/**
* Asserts that {@code expected} and {@code actual} int arrays are equal.
* If both are {@code null}, they are considered equal.
*/
public static void assertArrayEquals(int[] expected, int[] actual) {
AssertArrayEquals.assertArrayEquals(expected, actual);
}
/**
* Asserts that {@code expected} and {@code actual} int arrays are equal.
*
If both are {@code null}, they are considered equal.
*
Fails with the supplied failure {@code message}.
*/
public static void assertArrayEquals(int[] expected, int[] actual, String message) {
AssertArrayEquals.assertArrayEquals(expected, actual, message);
}
/**
* Asserts that {@code expected} and {@code actual} int arrays are equal.
*
If both are {@code null}, they are considered equal.
*
If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertArrayEquals(int[] expected, int[] actual, Supplier messageSupplier) {
AssertArrayEquals.assertArrayEquals(expected, actual, messageSupplier);
}
/**
* Asserts that {@code expected} and {@code actual} long arrays are equal.
* If both are {@code null}, they are considered equal.
*/
public static void assertArrayEquals(long[] expected, long[] actual) {
AssertArrayEquals.assertArrayEquals(expected, actual);
}
/**
* Asserts that {@code expected} and {@code actual} long arrays are equal.
*
If both are {@code null}, they are considered equal.
*
Fails with the supplied failure {@code message}.
*/
public static void assertArrayEquals(long[] expected, long[] actual, String message) {
AssertArrayEquals.assertArrayEquals(expected, actual, message);
}
/**
* Asserts that {@code expected} and {@code actual} long arrays are equal.
*
If both are {@code null}, they are considered equal.
*
If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertArrayEquals(long[] expected, long[] actual, Supplier messageSupplier) {
AssertArrayEquals.assertArrayEquals(expected, actual, messageSupplier);
}
/**
* Asserts that {@code expected} and {@code actual} float arrays are equal.
* Equality imposed by this method is consistent with {@link Float#equals(Object)} and
* {@link Float#compare(float, float)}.
*/
public static void assertArrayEquals(float[] expected, float[] actual) {
AssertArrayEquals.assertArrayEquals(expected, actual);
}
/**
* Asserts that {@code expected} and {@code actual} float arrays are equal.
* Equality imposed by this method is consistent with {@link Float#equals(Object)} and
* {@link Float#compare(float, float)}.
* Fails with the supplied failure {@code message}.
*/
public static void assertArrayEquals(float[] expected, float[] actual, String message) {
AssertArrayEquals.assertArrayEquals(expected, actual, message);
}
/**
* Asserts that {@code expected} and {@code actual} float arrays are equal.
*
Equality imposed by this method is consistent with {@link Float#equals(Object)} and
* {@link Float#compare(float, float)}.
* If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertArrayEquals(float[] expected, float[] actual, Supplier messageSupplier) {
AssertArrayEquals.assertArrayEquals(expected, actual, messageSupplier);
}
/**
* Asserts that {@code expected} and {@code actual} float arrays are equal within the given {@code delta}.
* Equality imposed by this method is consistent with {@link Float#equals(Object)} and
* {@link Float#compare(float, float)}.
*/
public static void assertArrayEquals(float[] expected, float[] actual, float delta) {
AssertArrayEquals.assertArrayEquals(expected, actual, delta);
}
/**
* Asserts that {@code expected} and {@code actual} float arrays are equal within the given {@code delta}.
* Equality imposed by this method is consistent with {@link Float#equals(Object)} and
* {@link Float#compare(float, float)}.
* Fails with the supplied failure {@code message}.
*/
public static void assertArrayEquals(float[] expected, float[] actual, float delta, String message) {
AssertArrayEquals.assertArrayEquals(expected, actual, delta, message);
}
/**
* Asserts that {@code expected} and {@code actual} float arrays are equal within the given {@code delta}.
*
Equality imposed by this method is consistent with {@link Float#equals(Object)} and
* {@link Float#compare(float, float)}.
* If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertArrayEquals(float[] expected, float[] actual, float delta,
Supplier messageSupplier) {
AssertArrayEquals.assertArrayEquals(expected, actual, delta, messageSupplier);
}
/**
* Asserts that {@code expected} and {@code actual} double arrays are equal.
* Equality imposed by this method is consistent with {@link Double#equals(Object)} and
* {@link Double#compare(double, double)}.
*/
public static void assertArrayEquals(double[] expected, double[] actual) {
AssertArrayEquals.assertArrayEquals(expected, actual);
}
/**
* Asserts that {@code expected} and {@code actual} double arrays are equal.
* Equality imposed by this method is consistent with {@link Double#equals(Object)} and
* {@link Double#compare(double, double)}.
* Fails with the supplied failure {@code message}.
*/
public static void assertArrayEquals(double[] expected, double[] actual, String message) {
AssertArrayEquals.assertArrayEquals(expected, actual, message);
}
/**
* Asserts that {@code expected} and {@code actual} double arrays are equal.
*
Equality imposed by this method is consistent with {@link Double#equals(Object)} and
* {@link Double#compare(double, double)}.
* If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertArrayEquals(double[] expected, double[] actual, Supplier messageSupplier) {
AssertArrayEquals.assertArrayEquals(expected, actual, messageSupplier);
}
/**
* Asserts that {@code expected} and {@code actual} double arrays are equal within the given {@code delta}.
* Equality imposed by this method is consistent with {@link Double#equals(Object)} and
* {@link Double#compare(double, double)}.
*/
public static void assertArrayEquals(double[] expected, double[] actual, double delta) {
AssertArrayEquals.assertArrayEquals(expected, actual, delta);
}
/**
* Asserts that {@code expected} and {@code actual} double arrays are equal within the given {@code delta}.
* Equality imposed by this method is consistent with {@link Double#equals(Object)} and
* {@link Double#compare(double, double)}.
* Fails with the supplied failure {@code message}.
*/
public static void assertArrayEquals(double[] expected, double[] actual, double delta, String message) {
AssertArrayEquals.assertArrayEquals(expected, actual, delta, message);
}
/**
* Asserts that {@code expected} and {@code actual} double arrays are equal within the given {@code delta}.
*
Equality imposed by this method is consistent with {@link Double#equals(Object)} and
* {@link Double#compare(double, double)}.
* If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertArrayEquals(double[] expected, double[] actual, double delta,
Supplier messageSupplier) {
AssertArrayEquals.assertArrayEquals(expected, actual, delta, messageSupplier);
}
/**
* Asserts that {@code expected} and {@code actual} object arrays are deeply equal.
* If both are {@code null}, they are considered equal.
*
Nested float arrays are checked as in {@link #assertEquals(float, float)}.
*
Nested double arrays are checked as in {@link #assertEquals(double, double)}.
*
* @see Objects#equals(Object, Object)
* @see Arrays#deepEquals(Object[], Object[])
*/
public static void assertArrayEquals(Object[] expected, Object[] actual) {
AssertArrayEquals.assertArrayEquals(expected, actual);
}
/**
* Asserts that {@code expected} and {@code actual} object arrays are deeply equal.
*
If both are {@code null}, they are considered equal.
*
Nested float arrays are checked as in {@link #assertEquals(float, float)}.
*
Nested double arrays are checked as in {@link #assertEquals(double, double)}.
*
Fails with the supplied failure {@code message}.
*
* @see Objects#equals(Object, Object)
* @see Arrays#deepEquals(Object[], Object[])
*/
public static void assertArrayEquals(Object[] expected, Object[] actual, String message) {
AssertArrayEquals.assertArrayEquals(expected, actual, message);
}
/**
* Asserts that {@code expected} and {@code actual} object arrays are deeply equal.
*
If both are {@code null}, they are considered equal.
*
Nested float arrays are checked as in {@link #assertEquals(float, float)}.
*
Nested double arrays are checked as in {@link #assertEquals(double, double)}.
*
If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*
* @see Objects#equals(Object, Object)
* @see Arrays#deepEquals(Object[], Object[])
*/
public static void assertArrayEquals(Object[] expected, Object[] actual, Supplier messageSupplier) {
AssertArrayEquals.assertArrayEquals(expected, actual, messageSupplier);
}
// --- assertIterableEquals --------------------------------------------
/**
* Asserts that {@code expected} and {@code actual} iterables are deeply equal.
* Similarly to the check for deep equality in {@link #assertArrayEquals(Object[], Object[])},
* if two iterables are encountered (including {@code expected} and {@code 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:
{@code
* import static java.util.Arrays.asList;
* . . .
* Iterable i0 = new ArrayList<>(asList(1, 2, 3));
* Iterable i1 = new LinkedList<>(asList(1, 2, 3));
* assertIterableEquals(i0, i1); // Passes
* }
* If both {@code expected} and {@code actual} are {@code null}, they are considered equal.
*
* @see Objects#equals(Object, Object)
* @see Arrays#deepEquals(Object[], Object[])
* @see #assertArrayEquals(Object[], Object[])
*/
public static void assertIterableEquals(Iterable> expected, Iterable> actual) {
AssertIterableEquals.assertIterableEquals(expected, actual);
}
/**
* Asserts that {@code expected} and {@code actual} iterables are deeply equal.
*
Similarly to the check for deep equality in
* {@link #assertArrayEquals(Object[], Object[], String)}, if two iterables are encountered
* (including {@code expected} and {@code 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:
{@code
* import static java.util.Arrays.asList;
* . . .
* Iterable i0 = new ArrayList<>(asList(1, 2, 3));
* Iterable i1 = new LinkedList<>(asList(1, 2, 3));
* assertIterableEquals(i0, i1); // Passes
* }
* If both {@code expected} and {@code actual} are {@code null}, they are considered equal.
*
Fails with the supplied failure {@code message}.
*
* @see Objects#equals(Object, Object)
* @see Arrays#deepEquals(Object[], Object[])
* @see #assertArrayEquals(Object[], Object[], String)
*/
public static void assertIterableEquals(Iterable> expected, Iterable> actual, String message) {
AssertIterableEquals.assertIterableEquals(expected, actual, message);
}
/**
* Asserts that {@code expected} and {@code actual} iterables are deeply equal.
*
Similarly to the check for deep equality in
* {@link #assertArrayEquals(Object[], Object[], Supplier)}, if two iterables are encountered
* (including {@code expected} and {@code 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:
{@code
* import static java.util.Arrays.asList;
* . . .
* Iterable i0 = new ArrayList<>(asList(1, 2, 3));
* Iterable i1 = new LinkedList<>(asList(1, 2, 3));
* assertIterableEquals(i0, i1); // Passes
* }
* If both {@code expected} and {@code actual} are {@code null}, they are considered equal.
*
If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*
* @see Objects#equals(Object, Object)
* @see Arrays#deepEquals(Object[], Object[])
* @see #assertArrayEquals(Object[], Object[], Supplier)
*/
public static void assertIterableEquals(Iterable> expected, Iterable> actual,
Supplier messageSupplier) {
AssertIterableEquals.assertIterableEquals(expected, actual, messageSupplier);
}
// --- assertNotEquals -----------------------------------------------------
/**
* Asserts that {@code expected} and {@code actual} are not equal.
* Fails if both are {@code null}.
*
* @see Object#equals(Object)
*/
public static void assertNotEquals(Object unexpected, Object actual) {
AssertNotEquals.assertNotEquals(unexpected, actual);
}
/**
* Asserts that {@code expected} and {@code actual} are not equal.
*
Fails if both are {@code null}.
*
Fails with the supplied failure {@code message}.
*
* @see Object#equals(Object)
*/
public static void assertNotEquals(Object unexpected, Object actual, String message) {
AssertNotEquals.assertNotEquals(unexpected, actual, message);
}
/**
* Asserts that {@code expected} and {@code actual} are not equal.
*
Fails if both are {@code null}.
*
If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*
* @see Object#equals(Object)
*/
public static void assertNotEquals(Object unexpected, Object actual, Supplier messageSupplier) {
AssertNotEquals.assertNotEquals(unexpected, actual, messageSupplier);
}
// --- assertSame ----------------------------------------------------------
/**
* Asserts that {@code expected} and {@code actual} refer to the same object.
*/
public static void assertSame(Object expected, Object actual) {
AssertSame.assertSame(expected, actual);
}
/**
* Asserts that {@code expected} and {@code actual} refer to the same object.
* Fails with the supplied failure {@code message}.
*/
public static void assertSame(Object expected, Object actual, String message) {
AssertSame.assertSame(expected, actual, message);
}
/**
* Asserts that {@code expected} and {@code actual} refer to the same object.
*
If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertSame(Object expected, Object actual, Supplier messageSupplier) {
AssertSame.assertSame(expected, actual, messageSupplier);
}
// --- assertNotSame -------------------------------------------------------
/**
* Asserts that {@code expected} and {@code actual} do not refer to the same object.
*/
public static void assertNotSame(Object unexpected, Object actual) {
AssertNotSame.assertNotSame(unexpected, actual);
}
/**
* Asserts that {@code expected} and {@code actual} do not refer to the same object.
* Fails with the supplied failure {@code message}.
*/
public static void assertNotSame(Object unexpected, Object actual, String message) {
AssertNotSame.assertNotSame(unexpected, actual, message);
}
/**
* Asserts that {@code expected} and {@code actual} do not refer to the same object.
*
If necessary, the failure message will be retrieved lazily from the supplied {@code messageSupplier}.
*/
public static void assertNotSame(Object unexpected, Object actual, Supplier messageSupplier) {
AssertNotSame.assertNotSame(unexpected, actual, messageSupplier);
}
// --- assertAll -----------------------------------------------------------
/**
* Asserts that all supplied {@code executables} do not throw an
* {@link AssertionError}.
*
* See Javadoc for {@link #assertAll(String, Stream)} for an explanation of this
* method's exception handling semantics.
*
* @see #assertAll(String, Executable...)
* @see #assertAll(Stream)
* @see #assertAll(String, Stream)
*/
@API(Experimental)
public static void assertAll(Executable... executables) throws MultipleFailuresError {
AssertAll.assertAll(executables);
}
/**
* Asserts that all supplied {@code executables} do not throw an
* {@link AssertionError}.
*
*
See Javadoc for {@link #assertAll(String, Stream)} for an explanation of this
* method's exception handling semantics.
*
* @see #assertAll(Executable...)
* @see #assertAll(String, Executable...)
* @see #assertAll(String, Stream)
*/
@API(Experimental)
public static void assertAll(Stream executables) throws MultipleFailuresError {
AssertAll.assertAll(executables);
}
/**
* Asserts that all supplied {@code executables} do not throw an
* {@link AssertionError}.
*
* See Javadoc for {@link #assertAll(String, Stream)} for an explanation of this
* method's exception handling semantics.
*
* @see #assertAll(Executable...)
* @see #assertAll(Stream)
* @see #assertAll(String, Stream)
*/
@API(Experimental)
public static void assertAll(String heading, Executable... executables) throws MultipleFailuresError {
AssertAll.assertAll(heading, executables);
}
/**
* Asserts that all supplied {@code executables} do not throw an
* {@link AssertionError}.
*
*
If any supplied {@link Executable} throws an {@code AssertionError}, all remaining
* {@code executables} will still be executed, and all failures will be aggregated
* and reported in a {@link MultipleFailuresError}. However, if an {@code executable}
* throws an exception that is not an {@code AssertionError}, execution will halt
* immediately, and the exception will be rethrown as is but
* {@link ExceptionUtils#throwAsUncheckedException masked} as an unchecked exception.
*
*
The supplied {@code heading} will be included in the message string for the
* {@link MultipleFailuresError}.
*
* @see #assertAll(Executable...)
* @see #assertAll(String, Executable...)
* @see #assertAll(Stream)
*/
@API(Experimental)
public static void assertAll(String heading, Stream executables) throws MultipleFailuresError {
AssertAll.assertAll(heading, executables);
}
// --- assert exceptions ---------------------------------------------------
/**
* Asserts that execution of the supplied {@code executable} throws
* an exception of the {@code 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 T assertThrows(Class extends Throwable> expectedType, Executable executable) {
return AssertThrows.assertThrows(expectedType, executable);
}
/**
* @deprecated Use {@link #assertThrows(Class, Executable)} instead.
*/
@Deprecated
public static T expectThrows(Class expectedType, Executable executable) {
return AssertThrows.expectThrows(expectedType, executable);
}
// --- assertTimeout -------------------------------------------------------
/**
* Asserts that execution of the supplied {@code executable}
* completes before the given {@code 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.
*
* @see #assertTimeout(Duration, Executable, String)
* @see #assertTimeout(Duration, Executable, Supplier)
* @see #assertTimeoutPreemptively(Duration, Executable)
*/
public static void assertTimeout(Duration timeout, Executable executable) {
AssertTimeout.assertTimeout(timeout, executable);
}
/**
* Asserts that execution of the supplied {@code executable}
* completes before the given {@code 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 {@code message}.
*
* @see #assertTimeout(Duration, Executable)
* @see #assertTimeout(Duration, Executable, Supplier)
* @see #assertTimeoutPreemptively(Duration, Executable, String)
*/
public static void assertTimeout(Duration timeout, Executable executable, String message) {
AssertTimeout.assertTimeout(timeout, executable, message);
}
/**
* Asserts that execution of the supplied {@code executable}
* completes before the given {@code 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 {@code messageSupplier}.
*
* @see #assertTimeout(Duration, Executable)
* @see #assertTimeout(Duration, Executable, String)
* @see #assertTimeoutPreemptively(Duration, Executable, Supplier)
*/
public static void assertTimeout(Duration timeout, Executable executable, Supplier messageSupplier) {
AssertTimeout.assertTimeout(timeout, executable, messageSupplier);
}
/**
* Asserts that execution of the supplied {@code executable}
* completes before the given {@code 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.
*
* @see #assertTimeoutPreemptively(Duration, Executable, String)
* @see #assertTimeoutPreemptively(Duration, Executable, Supplier)
* @see #assertTimeout(Duration, Executable)
*/
public static void assertTimeoutPreemptively(Duration timeout, Executable executable) {
AssertTimeout.assertTimeoutPreemptively(timeout, executable);
}
/**
* Asserts that execution of the supplied {@code executable}
* completes before the given {@code 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 {@code message}.
*
* @see #assertTimeoutPreemptively(Duration, Executable)
* @see #assertTimeoutPreemptively(Duration, Executable, Supplier)
* @see #assertTimeout(Duration, Executable, String)
*/
public static void assertTimeoutPreemptively(Duration timeout, Executable executable, String message) {
AssertTimeout.assertTimeoutPreemptively(timeout, executable, message);
}
/**
* Asserts that execution of the supplied {@code executable}
* completes before the given {@code 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 {@code messageSupplier}.
*
* @see #assertTimeoutPreemptively(Duration, Executable)
* @see #assertTimeoutPreemptively(Duration, Executable, String)
* @see #assertTimeout(Duration, Executable, Supplier)
*/
public static void assertTimeoutPreemptively(Duration timeout, Executable executable,
Supplier messageSupplier) {
AssertTimeout.assertTimeoutPreemptively(timeout, executable, messageSupplier);
}
}