LANG-1081: DiffBuilder.append(String, Object left, Object right) does not do a left.equals(right) check. This fixes #41 from github. Thanks to Jonathan Baker.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1654137 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3181b40766
commit
ffc38b1f3b
|
@ -22,6 +22,7 @@
|
|||
<body>
|
||||
|
||||
<release version="3.4" date="tba" description="tba">
|
||||
<action issue="LANG-1081" type="fix" dev="britter" due-to="Jonathan Baker">DiffBuilder.append(String, Object left, Object right) does not do a left.equals(right) check</action>
|
||||
<action issue="LANG-1055" type="fix" dev="britter" due-to="Jonathan Baker">StrSubstitutor.replaceSystemProperties does not work consistently</action>
|
||||
<action issue="LANG-1082" type="add" dev="britter" due-to="Jonathan Baker">Add option to disable the "objectsTriviallyEqual" test in DiffBuilder</action>
|
||||
<action issue="LANG-1083" type="fix" dev="britter" due-to="Jonathan Baker">Add (T) casts to get unit tests to pass in old JDK</action>
|
||||
|
|
|
@ -882,6 +882,10 @@ public class DiffBuilder implements Builder<DiffResult> {
|
|||
}
|
||||
|
||||
// Not array type
|
||||
if (lhs != null ? lhs.equals(rhs) : rhs.equals(lhs)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
diffs.add(new Diff<Object>(fieldName) {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
|
|
@ -19,7 +19,9 @@ 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.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.hamcrest.Matcher;
|
||||
|
@ -321,18 +323,56 @@ public class DiffBuilderTest {
|
|||
assertEquals(class1.objectField, diff.getLeft());
|
||||
assertEquals(class2.objectField, diff.getRight());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test that "left" and "right" are the same instance and are equal.
|
||||
*/
|
||||
@Test
|
||||
public void testObjectsEqual() throws Exception {
|
||||
final TypeTestClass class1 = new TypeTestClass();
|
||||
final TypeTestClass class2 = new TypeTestClass();
|
||||
class1.objectField = "Some string";
|
||||
class2.objectField = "Some string";
|
||||
final DiffResult list = class1.diff(class2);
|
||||
public void testObjectsSameAndEqual() throws Exception {
|
||||
final Integer sameObject = 1;
|
||||
final TypeTestClass left = new TypeTestClass();
|
||||
left.objectField = sameObject;
|
||||
final TypeTestClass right = new TypeTestClass();
|
||||
right.objectField = sameObject;
|
||||
assertTrue(left.objectField == right.objectField);
|
||||
assertTrue(left.objectField.equals(right.objectField));
|
||||
|
||||
final DiffResult list = left.diff(right);
|
||||
assertEquals(0, list.getNumberOfDiffs());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Test that "left" and "right" are the same instance but are equal.
|
||||
*/
|
||||
@Test
|
||||
public void testObjectsNotSameButEqual() throws Exception {
|
||||
final TypeTestClass left = new TypeTestClass();
|
||||
left.objectField = new Integer(1);
|
||||
final TypeTestClass right = new TypeTestClass();
|
||||
right.objectField = new Integer(1);
|
||||
assertFalse(left.objectField == right.objectField);
|
||||
assertTrue(left.objectField.equals(right.objectField));
|
||||
|
||||
final DiffResult list = left.diff(right);
|
||||
assertEquals(0, list.getNumberOfDiffs());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that "left" and "right" are not the same instance and are not equal.
|
||||
*/
|
||||
@Test
|
||||
public void testObjectsNotSameNorEqual() throws Exception {
|
||||
final TypeTestClass left = new TypeTestClass();
|
||||
left.objectField = 4;
|
||||
final TypeTestClass right = new TypeTestClass();
|
||||
right.objectField = 100;
|
||||
assertFalse(left.objectField == right.objectField);
|
||||
assertFalse(left.objectField.equals(right.objectField));
|
||||
|
||||
final DiffResult list = left.diff(right);
|
||||
assertEquals(1, list.getNumberOfDiffs());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectArray() throws Exception {
|
||||
final TypeTestClass class1 = new TypeTestClass();
|
||||
|
|
Loading…
Reference in New Issue