Skip to content

Commit fbbff9c

Browse files
committed
Adds test where elements from 2 generic types are cast to their type
1 parent 6a81d7f commit fbbff9c

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

  • equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract

equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ public void succeed_whenToStringLooksAtNonCollectionGenericContent() {
9090
EqualsVerifier.forClass(SparseArrayToStringContainer.class).verify();
9191
}
9292

93+
@Test
94+
public void succeed_whenEqualsLooksAtGenericContent_givenTwoGenericFields() {
95+
EqualsVerifier.forClass(TwoGenericsContainerWithIntrospection.class).verify();
96+
}
97+
9398
@Test
9499
public void succeed_whenClassHasTypeVariableThatExtendsSomething() {
95100
EqualsVerifier.forClass(TypeVariableExtendsContainer.class).verify();
@@ -745,6 +750,38 @@ public String toString() {
745750
}
746751
}
747752

753+
public static final class TwoGenericsContainerWithIntrospection {
754+
755+
private final List<String> stringList = new ArrayList<>();
756+
private final List<Integer> intList = new ArrayList<>();
757+
758+
@SuppressWarnings("unused")
759+
@Override
760+
public boolean equals(Object obj) {
761+
if (stringList != null && stringList.size() > 0) {
762+
String key = stringList.get(0); // force a cast
763+
}
764+
if (intList != null && intList.size() > 0) {
765+
Integer key = intList.get(0); // force a cast
766+
}
767+
768+
if (!(obj instanceof TwoGenericsContainerWithIntrospection)) {
769+
return false;
770+
}
771+
TwoGenericsContainerWithIntrospection other =
772+
(TwoGenericsContainerWithIntrospection) obj;
773+
return (
774+
Objects.equals(stringList, other.stringList) &&
775+
Objects.equals(intList, other.intList)
776+
);
777+
}
778+
779+
@Override
780+
public int hashCode() {
781+
return Objects.hash(stringList, intList);
782+
}
783+
}
784+
748785
@SuppressWarnings("unused")
749786
static final class TypeVariableExtendsContainer<I extends Comparable<I>> {
750787

0 commit comments

Comments
 (0)