diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 8fbffc33a..9c9f63a95 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -22,6 +22,7 @@
+ * Constructs a builder for the specified objects with the specified style. + *
+ * + *+ * If {@code lhs == rhs} or {@code lhs.equals(rhs)} then the builder will + * not evaluate any calls to {@code append(...)} and will return an empty + * {@link DiffResult} when {@link #build()} is executed. + *
+ * + *+ * This delegates to {@link #DiffBuilder(Object, Object, ToStringStyle, boolean)} + * with the testTriviallyEqual flag enabled. + *
+ * + * @param lhs + * {@code this} object + * @param rhs + * the object to diff against + * @param style + * the style will use when outputting the objects, {@code null} + * uses the default + * @throws IllegalArgumentException + * if {@code lhs} or {@code rhs} is {@code null} + */ + public DiffBuilder(final Object lhs, final Object rhs, + final ToStringStyle style) { + + this(lhs, rhs, style, true); } /** diff --git a/src/test/java/org/apache/commons/lang3/builder/DiffBuilderTest.java b/src/test/java/org/apache/commons/lang3/builder/DiffBuilderTest.java index db0950494..ae835fef8 100644 --- a/src/test/java/org/apache/commons/lang3/builder/DiffBuilderTest.java +++ b/src/test/java/org/apache/commons/lang3/builder/DiffBuilderTest.java @@ -16,10 +16,13 @@ */ package org.apache.commons.lang3.builder; +import static org.hamcrest.core.IsEqual.equalTo; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; import org.apache.commons.lang3.ArrayUtils; +import org.hamcrest.Matcher; import org.junit.Test; @@ -412,4 +415,44 @@ public class DiffBuilderTest { list = class1.diff(class1); assertEquals(ToStringStyle.MULTI_LINE_STYLE, list.getToStringStyle()); } + + @Test + public void testTriviallyEqualTestDisabled() { + final Matcher