Skip to content

Commit 25918c0

Browse files
committed
Tests a custom collection and map with EqualsBuilder.reflectionEquals
1 parent a8bc9f3 commit 25918c0

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/test/java/org/apache/commons/lang3/builder/EqualsBuilderTest.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import java.math.BigInteger;
2828
import java.util.ArrayList;
2929
import java.util.Arrays;
30+
import java.util.HashMap;
3031
import java.util.List;
32+
import java.util.Map;
3133

3234
import org.apache.commons.lang3.AbstractLangTest;
3335
import org.apache.commons.lang3.reflect.MethodUtils;
@@ -69,6 +71,19 @@ public int hashCode() {
6971
}
7072
}
7173

74+
static class TestArrayList extends ArrayList<String> {
75+
76+
private static final long serialVersionUID = 1L;
77+
78+
private final int extra;
79+
80+
TestArrayList(final int extra, final String... elements) {
81+
super(Arrays.asList(elements));
82+
this.extra = extra;
83+
}
84+
85+
}
86+
7287
public static class TestBCanEqualA {
7388
private final int b;
7489

@@ -106,6 +121,19 @@ static class TestEmptySubObject extends TestObject {
106121
}
107122
}
108123

124+
static class TestHashMap extends HashMap<String, String> {
125+
126+
private static final long serialVersionUID = 1L;
127+
128+
private final int extra;
129+
130+
TestHashMap(final int extra, final Map<String, String> map) {
131+
super(map);
132+
this.extra = extra;
133+
}
134+
135+
}
136+
109137
static class TestObject {
110138
private int a;
111139

@@ -1381,6 +1409,18 @@ private void testReflectionHierarchyEquals(final boolean testTransients) {
13811409
assertFalse(EqualsBuilder.reflectionEquals(tso1, this));
13821410
}
13831411

1412+
@Test
1413+
void testReflectionOnCustomArrayList() {
1414+
assertTrue(EqualsBuilder.reflectionEquals(new TestArrayList(1, "2", "3", "4"), new TestArrayList(1, "2", "3", "4")));
1415+
assertFalse(EqualsBuilder.reflectionEquals(new TestArrayList(1, "2", "3", "4"), new TestArrayList(2, "2", "3", "4")));
1416+
}
1417+
1418+
@Test
1419+
void testReflectionOnCustomHashMap() {
1420+
assertTrue(EqualsBuilder.reflectionEquals(new TestHashMap(1, new HashMap<>()), new TestHashMap(1, new HashMap<>())));
1421+
assertFalse(EqualsBuilder.reflectionEquals(new TestHashMap(1, new HashMap<>()), new TestHashMap(2, new HashMap<>())));
1422+
}
1423+
13841424
@Test
13851425
void testReset() {
13861426
final EqualsBuilder equalsBuilder = new EqualsBuilder();

0 commit comments

Comments
 (0)