1 package org.pojomatic.junit; 2 3 import org.pojomatic.Pojomatic; 4 import org.pojomatic.test.AssertUtils; 5 6 /** 7 * Pojomatic-related JUnit-style assertion methods useful for writing tests. 8 * @see org.junit.Assert 9 */ 10 public class PojomaticAssert { 11 12 /** 13 * Asserts that two objects are either both null or are equal according to 14 * {@link Object#equals(Object)}. If not, an {@code AssertionError} is thrown. If the objects are 15 * not equal, but the types of two objects are compatible for equality, then the differences as 16 * determined by {@link Pojomatic#diff(Object, Object)} are included in the failure message. 17 * 18 * @param expected the expected object 19 * @param actual the object which should be tested to equal the expected object 20 * @throws AssertionError if the objects are not equal. 21 * @see #assertEqualsWithDiff(String, Object, Object) 22 */ 23 public static void assertEqualsWithDiff(Object expected, Object actual) { 24 assertEqualsWithDiff(null, expected, actual); 25 } 26 27 /** 28 * Asserts that two objects are either both null or are equal according to 29 * {@link Object#equals(Object)}. If not, an {@code AssertionError} is thrown. If the objects are 30 * not equal, but the types of two objects are compatible for equality, then the differences as 31 * determined by {@link Pojomatic#diff(Object, Object)} are included in the failure message. 32 * @param message a message (possibly {@code null}) to include at the beginning of the 33 * {@code AssertionError} message. 34 * @param expected the expected object 35 * @param actual the object which should be tested to equal the expected object 36 * 37 * @throws AssertionError if the objects are not equal. 38 */ 39 public static void assertEqualsWithDiff(String message, Object expected, Object actual) { 40 AssertUtils.assertEquals(message, expected, actual); 41 } 42 43 private PojomaticAssert() {} 44 }