Fix: CompareTo when discriminatorString is null

This commit is contained in:
Rob Bygrave
2022-04-21 07:50:53 +02:00
committed by Noemi Szemenyei
parent da2b14530b
commit 0c0484c56e
2 changed files with 24 additions and 7 deletions
@@ -259,15 +259,11 @@ public final class DeployInheritInfo implements Comparable<DeployInheritInfo> {
}
@Override
public int compareTo(DeployInheritInfo o) {
if (o == this) {
public int compareTo(DeployInheritInfo other) {
if (other == this) {
return 0;
} else if (o.discriminatorStringValue == null) {
return 1;
} else if (discriminatorStringValue == null) {
return -1;
} else {
return type.getName().compareTo(o.getType().getName());
return type.getName().compareTo(other.type.getName());
}
}
@@ -0,0 +1,21 @@
package io.ebeaninternal.server.deploy.parse;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
class DeployInheritInfoTest {
@Test
void addChild_when_DiscriminatorValueIsNull() {
DeployInheritInfo root = new DeployInheritInfo(Object.class);
root.addChild(new DeployInheritInfo(Integer.class)); // DiscriminatorValue is null
root.addChild(new DeployInheritInfo(Short.class)); // DiscriminatorValue is null
DeployInheritInfo c2 = new DeployInheritInfo(Long.class);
c2.setDiscriminatorValue("c2");
root.addChild(c2);
assertThat(root.children()).hasSize(3);
}
}