
de.larssh.utils.test.Assertions Maven / Gradle / Ivy
// Generated by delombok at Thu Feb 27 09:09:15 CET 2020
package de.larssh.utils.test;
import static java.util.stream.Collectors.joining;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import java.util.Arrays;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.IntStream;
import org.jooq.lambda.function.Consumer3;
import org.joor.Reflect;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
/**
* This class contains helper methods for assertion.
*/
public final class Assertions {
/**
* Asserts that the methods {@link Object#equals(Object)} and
* {@link Object#hashCode()} of objects created by executing the {@code clazz}es
* constructor work as defined by {@code arguments}.
*
*
* The constructor of {@code clazz} is called multiple times using different
* combinations of arguments. The resulting objects equality is checked using
* declarations of {@code arguments}.
* {@link Reflects#create(Reflect, Object...)} is used to construct instances of
* {@code clazz}.
*
*
* {@code arguments} declares two kind of valid arguments for the class
* constructor and if changing the argument should change the objects equality.
*
*
* In addition to argument checks {@link Object#equals(Object)} is checked
* against {@code null}, {@code true} and the object itself while the first two
* are expected to differ from the object itself.
*
* @param clazz class to be instantiated based on given arguments
* @param arguments declaration of arguments and if changing arguments should
* change equality
*/
public static void assertEqualsAndHashCode(final Class> clazz, final AssertEqualsAndHashCodeArguments arguments) {
final Reflect reflect = Reflect.onClass(clazz);
assertEqualsAndHashCode(a -> Reflects.create(reflect, a).get(), arguments);
}
/**
* Asserts that the methods {@link Object#equals(Object)} and
* {@link Object#hashCode()} of objects created by executing {@code constructor}
* work as defined by {@code arguments}.
*
*
* {@code constructor} is called multiple times using different combinations of
* arguments. The resulting objects equality is checked using declarations of
* {@code arguments}.
*
*
* {@code arguments} declares two kind of valid arguments for the constructor
* and if changing the argument should change the objects equality.
*
*
* In addition to argument checks {@link Object#equals(Object)} is checked
* against {@code null}, {@code true} and the object itself while the first two
* are expected to differ from the object itself.
*
* @param constructor function to construct object instances based on given
* arguments
* @param arguments declaration of arguments and if changing arguments should
* change equality
*/
@SuppressFBWarnings(value = "PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS", justification = "need to call constructor twice to validate equals")
public static void assertEqualsAndHashCode(final Function