From 41f0246333550c754c62df964650635474925a30 Mon Sep 17 00:00:00 2001 From: Jan Ouwens Date: Tue, 26 Nov 2024 10:04:50 +0100 Subject: [PATCH] Adds additional generics test --- .../extended_contract/GenericTypesTest.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java index 822567528..554c4ab08 100644 --- a/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java +++ b/equalsverifier-core/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/GenericTypesTest.java @@ -15,6 +15,11 @@ public class GenericTypesTest { + @Test + public void succeed_whenClassHasGenericFieldThatsSpecifiedToABuiltinGeneric() { + EqualsVerifier.forClass(GenericContainerWithBuiltin.class).verify(); + } + @Test public void succeed_whenEqualsLooksAtJava8TypesGenericContent() { EqualsVerifier.forClass(JavaGenericTypeContainer.class).verify(); @@ -121,6 +126,29 @@ public void succeed_whenClassHasASelfReferenceGenericParameter_givenPrefabValues .verify(); } + static final class GenericContainerWithBuiltin { + + private final Generic> b; + + public GenericContainerWithBuiltin(Generic> b) { + this.b = b; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof GenericContainerWithBuiltin)) { + return false; + } + GenericContainerWithBuiltin other = (GenericContainerWithBuiltin) obj; + return Objects.equals(b, other.b); + } + + @Override + public int hashCode() { + return Objects.hash(b); + } + } + static final class JavaGenericTypeContainer { private final Optional optional; @@ -172,6 +200,30 @@ public String toString() { } } + static final class Generic { + + private final T t; + + public Generic(T t) { + this.t = t; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Generic)) { + return false; + } + @SuppressWarnings("unchecked") + Generic other = (Generic) obj; + return Objects.equals(t, other.t); + } + + @Override + public int hashCode() { + return Objects.hash(t); + } + } + static final class ListContainer { private final List list;