-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds test case for sealed interface recursion
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
...t/java/nl/jqno/equalsverifier/integration/extended_contract/SealedTypesRecursionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |