-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for jakarta.persistence's entity and Id annotations
- Loading branch information
Showing
3 changed files
with
1,109 additions
and
0 deletions.
There are no files selected for viewing
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
148 changes: 148 additions & 0 deletions
148
src/test/java/nl/jqno/equalsverifier/integration/extra_features/JakartaEntityTest.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,148 @@ | ||
package nl.jqno.equalsverifier.integration.extra_features; | ||
|
||
import static nl.jqno.equalsverifier.testhelpers.Util.defaultHashCode; | ||
|
||
import java.util.Objects; | ||
import nl.jqno.equalsverifier.EqualsVerifier; | ||
import nl.jqno.equalsverifier.testhelpers.ExpectedException; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class JakartaEntityTest { | ||
|
||
@Test | ||
public void succeed_whenClassIsNonFinalAndFieldsAreMutable_givenClassHasJpaEntityAnnotation() { | ||
EqualsVerifier.forClass(EntityByJakartaAnnotation.class).verify(); | ||
} | ||
|
||
@Test | ||
public void fail_whenClassIsNonFinalAndFieldsAreMutable_givenSuperclassHasJpaEntityAnnotationButThisClassDoesnt() { | ||
ExpectedException | ||
.when(() -> EqualsVerifier.forClass(SubclassEntityByJakartaAnnotation.class).verify()) | ||
.assertFailure() | ||
.assertMessageContains("Subclass"); | ||
} | ||
|
||
@Test | ||
public void succeed_whenFieldsAreMutable_givenClassHasJpaEmbeddableAnnotation() { | ||
EqualsVerifier.forClass(EmbeddableByJakartaAnnotation.class).verify(); | ||
} | ||
|
||
@Test | ||
public void fail_whenFieldsAreMutable_givenSuperclassHasJpaEmbeddableAnnotationButThisClassDoesnt() { | ||
ExpectedException | ||
.when(() -> | ||
EqualsVerifier.forClass(SubclassEmbeddableByJakartaAnnotation.class).verify() | ||
) | ||
.assertFailure() | ||
.assertMessageContains("Subclass"); | ||
} | ||
|
||
@Test | ||
public void succeed_whenFieldsAreMutable_givenClassHasJpaMappedSuperclassAnnotation() { | ||
EqualsVerifier.forClass(MappedSuperclassByJakartaAnnotation.class).verify(); | ||
} | ||
|
||
@Test | ||
public void fail_whenFieldsAreMutable_givenSuperclassHasJpaMappedSuperclassAnnotationButThisClassDoesnt() { | ||
ExpectedException | ||
.when(() -> | ||
EqualsVerifier.forClass(SubclassMappedSuperclassByJakartaAnnotation.class).verify() | ||
) | ||
.assertFailure() | ||
.assertMessageContains("Subclass"); | ||
} | ||
|
||
@jakarta.persistence.Entity | ||
static class EntityByJakartaAnnotation { | ||
|
||
private int i; | ||
private String s; | ||
|
||
public void setI(int value) { | ||
this.i = value; | ||
} | ||
|
||
public void setS(String value) { | ||
this.s = value; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (!(obj instanceof EntityByJakartaAnnotation)) { | ||
return false; | ||
} | ||
EntityByJakartaAnnotation other = (EntityByJakartaAnnotation) obj; | ||
return i == other.i && Objects.equals(s, other.s); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return defaultHashCode(this); | ||
} | ||
} | ||
|
||
static class SubclassEntityByJakartaAnnotation extends EntityByJakartaAnnotation {} | ||
|
||
@jakarta.persistence.Embeddable | ||
static class EmbeddableByJakartaAnnotation { | ||
|
||
private int i; | ||
private String s; | ||
|
||
public void setI(int value) { | ||
this.i = value; | ||
} | ||
|
||
public void setS(String value) { | ||
this.s = value; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (!(obj instanceof EmbeddableByJakartaAnnotation)) { | ||
return false; | ||
} | ||
EmbeddableByJakartaAnnotation other = (EmbeddableByJakartaAnnotation) obj; | ||
return i == other.i && Objects.equals(s, other.s); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return defaultHashCode(this); | ||
} | ||
} | ||
|
||
static class SubclassEmbeddableByJakartaAnnotation extends EmbeddableByJakartaAnnotation {} | ||
|
||
@jakarta.persistence.MappedSuperclass | ||
abstract static class MappedSuperclassByJakartaAnnotation { | ||
|
||
private int i; | ||
private String s; | ||
|
||
public void setI(int value) { | ||
this.i = value; | ||
} | ||
|
||
public void setS(String value) { | ||
this.s = value; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (!(obj instanceof MappedSuperclassByJakartaAnnotation)) { | ||
return false; | ||
} | ||
MappedSuperclassByJakartaAnnotation other = (MappedSuperclassByJakartaAnnotation) obj; | ||
return i == other.i && Objects.equals(s, other.s); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return defaultHashCode(this); | ||
} | ||
} | ||
|
||
static class SubclassMappedSuperclassByJakartaAnnotation | ||
extends MappedSuperclassByJakartaAnnotation {} | ||
} |
Oops, something went wrong.