Skip to content

Commit

Permalink
Adds additional generics test
Browse files Browse the repository at this point in the history
  • Loading branch information
jqno committed Dec 4, 2024
1 parent c0d03df commit ec8320d
Showing 1 changed file with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -121,6 +126,29 @@ public void succeed_whenClassHasASelfReferenceGenericParameter_givenPrefabValues
.verify();
}

static final class GenericContainerWithBuiltin {

private final Generic<List<String>> b;

public GenericContainerWithBuiltin(Generic<List<String>> 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<Point> optional;
Expand Down Expand Up @@ -172,6 +200,30 @@ public String toString() {
}
}

static final class Generic<T> {

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<T> other = (Generic<T>) obj;
return Objects.equals(t, other.t);
}

@Override
public int hashCode() {
return Objects.hash(t);
}
}

static final class ListContainer {

private final List<Point> list;
Expand Down

0 comments on commit ec8320d

Please sign in to comment.