TSK-950: Test pojo implementation of equals and hashcode
This commit is contained in:
parent
5b74398e90
commit
0877e946a9
|
|
@ -102,6 +102,12 @@
|
||||||
<version>${version.log4j}</version>
|
<version>${version.log4j}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>nl.jqno.equalsverifier</groupId>
|
||||||
|
<artifactId>equalsverifier</artifactId>
|
||||||
|
<version>${version.equalsverifier}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<!-- this repository is needed to fetch com.ibm.db2.jcc -->
|
<!-- this repository is needed to fetch com.ibm.db2.jcc -->
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ public class KeyDomain {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getClass() != obj.getClass()) {
|
if (!getClass().isAssignableFrom(obj.getClass())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
KeyDomain other = (KeyDomain) obj;
|
KeyDomain other = (KeyDomain) obj;
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ public class ObjectReference {
|
||||||
if (other == null) {
|
if (other == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (other.getClass() != getClass()) {
|
if (!getClass().isAssignableFrom(other.getClass())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ObjectReference o = (ObjectReference) other;
|
ObjectReference o = (ObjectReference) other;
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ public class TimeInterval {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getClass() != obj.getClass()) {
|
if (!getClass().isAssignableFrom(obj.getClass())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
TimeInterval other = (TimeInterval) obj;
|
TimeInterval other = (TimeInterval) obj;
|
||||||
|
|
|
||||||
|
|
@ -166,7 +166,7 @@ public class AttachmentImpl implements Attachment {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getClass() != obj.getClass()) {
|
if (!getClass().isAssignableFrom(obj.getClass())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
AttachmentImpl other = (AttachmentImpl) obj;
|
AttachmentImpl other = (AttachmentImpl) obj;
|
||||||
|
|
|
||||||
|
|
@ -161,7 +161,7 @@ public class AttachmentSummaryImpl implements AttachmentSummary {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!(obj instanceof AttachmentSummaryImpl)) {
|
if (!getClass().isAssignableFrom(obj.getClass())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
AttachmentSummaryImpl other = (AttachmentSummaryImpl) obj;
|
AttachmentSummaryImpl other = (AttachmentSummaryImpl) obj;
|
||||||
|
|
|
||||||
|
|
@ -134,13 +134,23 @@ public class ClassificationImpl extends ClassificationSummaryImpl implements Cla
|
||||||
if (this == o) {
|
if (this == o) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (o == null || getClass() != o.getClass()) {
|
if (o == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!getClass().isAssignableFrom(o.getClass())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!super.equals(o)) {
|
if (!super.equals(o)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ClassificationImpl that = (ClassificationImpl) o;
|
ClassificationImpl that = (ClassificationImpl) o;
|
||||||
|
|
||||||
|
if (!that.canEqual(this)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return Objects.equals(isValidInDomain, that.isValidInDomain)
|
return Objects.equals(isValidInDomain, that.isValidInDomain)
|
||||||
&& Objects.equals(created, that.created)
|
&& Objects.equals(created, that.created)
|
||||||
&& Objects.equals(modified, that.modified)
|
&& Objects.equals(modified, that.modified)
|
||||||
|
|
@ -148,6 +158,10 @@ public class ClassificationImpl extends ClassificationSummaryImpl implements Cla
|
||||||
&& Objects.equals(applicationEntryPoint, that.applicationEntryPoint);
|
&& Objects.equals(applicationEntryPoint, that.applicationEntryPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean canEqual(Object other) {
|
||||||
|
return (other instanceof ClassificationImpl);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(super.hashCode(), isValidInDomain, created, modified, description, applicationEntryPoint);
|
return Objects.hash(super.hashCode(), isValidInDomain, created, modified, description, applicationEntryPoint);
|
||||||
|
|
|
||||||
|
|
@ -198,10 +198,20 @@ public class ClassificationSummaryImpl implements ClassificationSummary {
|
||||||
if (this == o) {
|
if (this == o) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (o == null || getClass() != o.getClass()) {
|
if (o == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!getClass().isAssignableFrom(o.getClass())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
ClassificationSummaryImpl that = (ClassificationSummaryImpl) o;
|
ClassificationSummaryImpl that = (ClassificationSummaryImpl) o;
|
||||||
|
|
||||||
|
if (!that.canEqual(this)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return priority == that.priority
|
return priority == that.priority
|
||||||
&& Objects.equals(id, that.id)
|
&& Objects.equals(id, that.id)
|
||||||
&& Objects.equals(key, that.key)
|
&& Objects.equals(key, that.key)
|
||||||
|
|
@ -222,6 +232,10 @@ public class ClassificationSummaryImpl implements ClassificationSummary {
|
||||||
&& Objects.equals(custom8, that.custom8);
|
&& Objects.equals(custom8, that.custom8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean canEqual(Object other) {
|
||||||
|
return (other instanceof ClassificationSummaryImpl);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(id, key, category, type, domain, name, parentId, parentKey, priority, serviceLevel, custom1,
|
return Objects.hash(id, key, category, type, domain, name, parentId, parentKey, priority, serviceLevel, custom1,
|
||||||
|
|
|
||||||
|
|
@ -774,7 +774,7 @@ public class TaskImpl implements Task {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getClass() != obj.getClass()) {
|
if (!getClass().isAssignableFrom(obj.getClass())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
TaskImpl other = (TaskImpl) obj;
|
TaskImpl other = (TaskImpl) obj;
|
||||||
|
|
|
||||||
|
|
@ -552,7 +552,7 @@ public class TaskSummaryImpl implements TaskSummary {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getClass() != obj.getClass()) {
|
if (!getClass().isAssignableFrom(obj.getClass())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
TaskSummaryImpl other = (TaskSummaryImpl) obj;
|
TaskSummaryImpl other = (TaskSummaryImpl) obj;
|
||||||
|
|
|
||||||
|
|
@ -461,6 +461,8 @@ public class WorkbasketAccessItemImpl implements WorkbasketAccessItem {
|
||||||
result = prime * result + (permRead ? 1231 : 1237);
|
result = prime * result + (permRead ? 1231 : 1237);
|
||||||
result = prime * result + (permTransfer ? 1231 : 1237);
|
result = prime * result + (permTransfer ? 1231 : 1237);
|
||||||
result = prime * result + ((workbasketId == null) ? 0 : workbasketId.hashCode());
|
result = prime * result + ((workbasketId == null) ? 0 : workbasketId.hashCode());
|
||||||
|
result = prime * result + ((workbasketKey == null) ? 0 : workbasketKey.hashCode());
|
||||||
|
result = prime * result + ((accessName == null) ? 0 : accessName.hashCode());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -472,7 +474,7 @@ public class WorkbasketAccessItemImpl implements WorkbasketAccessItem {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getClass() != obj.getClass()) {
|
if (!getClass().isAssignableFrom(obj.getClass())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
WorkbasketAccessItemImpl other = (WorkbasketAccessItemImpl) obj;
|
WorkbasketAccessItemImpl other = (WorkbasketAccessItemImpl) obj;
|
||||||
|
|
@ -548,6 +550,20 @@ public class WorkbasketAccessItemImpl implements WorkbasketAccessItem {
|
||||||
} else if (!workbasketId.equals(other.workbasketId)) {
|
} else if (!workbasketId.equals(other.workbasketId)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (workbasketKey == null) {
|
||||||
|
if (other.workbasketKey != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!workbasketKey.equals(other.workbasketKey)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (accessName == null) {
|
||||||
|
if (other.accessName != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!accessName.equals(other.accessName)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package pro.taskana.impl;
|
package pro.taskana.impl;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
|
||||||
import pro.taskana.Workbasket;
|
import pro.taskana.Workbasket;
|
||||||
import pro.taskana.WorkbasketSummary;
|
import pro.taskana.WorkbasketSummary;
|
||||||
import pro.taskana.WorkbasketType;
|
import pro.taskana.WorkbasketType;
|
||||||
|
|
@ -262,7 +263,8 @@ public class WorkbasketImpl implements Workbasket {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getClass() != obj.getClass()) {
|
|
||||||
|
if (!getClass().isAssignableFrom(obj.getClass())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
WorkbasketImpl other = (WorkbasketImpl) obj;
|
WorkbasketImpl other = (WorkbasketImpl) obj;
|
||||||
|
|
|
||||||
|
|
@ -263,7 +263,7 @@ public class WorkbasketSummaryImpl implements WorkbasketSummary {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getClass() != obj.getClass()) {
|
if (!getClass().isAssignableFrom(obj.getClass())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
WorkbasketSummaryImpl other = (WorkbasketSummaryImpl) obj;
|
WorkbasketSummaryImpl other = (WorkbasketSummaryImpl) obj;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
package pro.taskana;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.DynamicTest;
|
||||||
|
import org.junit.jupiter.api.TestFactory;
|
||||||
|
|
||||||
|
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||||
|
import nl.jqno.equalsverifier.Warning;
|
||||||
|
import pro.taskana.impl.AttachmentImpl;
|
||||||
|
import pro.taskana.impl.AttachmentSummaryImpl;
|
||||||
|
import pro.taskana.impl.ClassificationImpl;
|
||||||
|
import pro.taskana.impl.ClassificationSummaryImpl;
|
||||||
|
import pro.taskana.impl.TaskImpl;
|
||||||
|
import pro.taskana.impl.TaskSummaryImpl;
|
||||||
|
import pro.taskana.impl.WorkbasketAccessItemImpl;
|
||||||
|
import pro.taskana.impl.WorkbasketImpl;
|
||||||
|
import pro.taskana.impl.WorkbasketSummaryImpl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check classes with a custom equals and hashcode implementation for correctness.
|
||||||
|
*/
|
||||||
|
class EqualsAndHashCodeTest {
|
||||||
|
|
||||||
|
@TestFactory
|
||||||
|
Collection<DynamicTest> equalsContract() {
|
||||||
|
return
|
||||||
|
getPojoClasses().stream()
|
||||||
|
.map(cl -> DynamicTest.dynamicTest("Check Hash and Equals for " + cl.getSimpleName(),
|
||||||
|
() -> {
|
||||||
|
EqualsVerifier.forClass(cl)
|
||||||
|
.suppress(Warning.NONFINAL_FIELDS, Warning.STRICT_INHERITANCE)
|
||||||
|
.withRedefinedSuperclass()
|
||||||
|
.verify();
|
||||||
|
}))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO find a way to dynamically create a list with custom implemented equals or hash methods.
|
||||||
|
private List<Class<?>> getPojoClasses() {
|
||||||
|
return Arrays.asList(
|
||||||
|
KeyDomain.class,
|
||||||
|
ObjectReference.class,
|
||||||
|
TimeInterval.class,
|
||||||
|
AttachmentImpl.class,
|
||||||
|
AttachmentSummaryImpl.class,
|
||||||
|
ClassificationImpl.class,
|
||||||
|
ClassificationSummaryImpl.class,
|
||||||
|
TaskImpl.class,
|
||||||
|
TaskSummaryImpl.class,
|
||||||
|
WorkbasketAccessItemImpl.class,
|
||||||
|
WorkbasketImpl.class,
|
||||||
|
WorkbasketSummaryImpl.class
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
1
pom.xml
1
pom.xml
|
|
@ -69,6 +69,7 @@
|
||||||
<version.mockito>2.8.47</version.mockito>
|
<version.mockito>2.8.47</version.mockito>
|
||||||
<version.powermock>1.7.1</version.powermock>
|
<version.powermock>1.7.1</version.powermock>
|
||||||
<version.hamcrest>1.3</version.hamcrest>
|
<version.hamcrest>1.3</version.hamcrest>
|
||||||
|
<version.equalsverifier>3.1.10</version.equalsverifier>
|
||||||
|
|
||||||
<!-- database driver versions -->
|
<!-- database driver versions -->
|
||||||
<version.h2>1.4.197</version.h2>
|
<version.h2>1.4.197</version.h2>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue