Skip to content

Commit

Permalink
Adds test case for sealed interface recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
jqno committed Feb 20, 2024
1 parent 11076b6 commit e958d17
Showing 1 changed file with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package nl.jqno.equalsverifier.integration.extended_contract;

import java.util.Objects;
import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning;
import org.junit.jupiter.api.Test;

class SealedTypesRecursionTest {

@Test
public void testEV() {
EqualsVerifier
.forClass(A.class)
.suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS)
.verify();
}

class A {

public I sealedClassField;

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

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof A)) {
return false;
}
A other = (A) obj;
return Objects.equals(sealedClassField, other.sealedClassField);
}
}

public sealed interface I permits E {}

public final class E implements I {

public A referenceToA;

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

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof E)) {
return false;
}
E other = (E) obj;
return Objects.equals(referenceToA, other.referenceToA);
}
}
}

0 comments on commit e958d17

Please sign in to comment.