templates.soft_assertions_entry_point_class_template.txt Maven / Gradle / Ivy
package ${package}; import static org.assertj.core.groups.Properties.extractProperty; import java.util.List; import org.assertj.core.internal.cglib.proxy.Enhancer; import org.assertj.core.api.ErrorCollector; import org.assertj.core.api.SoftAssertionError; /** * Entry point for assertions of different data types. Each method in this class is a static factory for the * type-specific assertion objects. */ public class SoftAssertions { /** Collects error messages of all AssertionErrors thrown by the proxied method. */ protected final ErrorCollector collector = new ErrorCollector(); /** Creates a new
{@link SoftAssertions}. */ public SoftAssertions() { } /** * Verifies that no proxied assertion methods have failed. * * @throws SoftAssertionError if any proxied assertion objects threw */ public void assertAll() { Listerrors = collector.errors(); if (!errors.isEmpty()) { throw new SoftAssertionError(extractProperty("message", String.class).from(errors)); } } @SuppressWarnings("unchecked") protected V proxy(Class assertClass, Class actualClass, T actual) { Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(assertClass); enhancer.setCallback(collector); return (V) enhancer.create(new Class[] { actualClass }, new Object[] { actual }); } ${all_assertions_entry_points} }