diff --git a/aether-datafixers-schema-tools/src/main/java/de/splatgames/aether/datafixers/schematools/introspection/FieldInfo.java b/aether-datafixers-schema-tools/src/main/java/de/splatgames/aether/datafixers/schematools/introspection/FieldInfo.java index c29b195..5b77283 100644 --- a/aether-datafixers-schema-tools/src/main/java/de/splatgames/aether/datafixers/schematools/introspection/FieldInfo.java +++ b/aether-datafixers-schema-tools/src/main/java/de/splatgames/aether/datafixers/schematools/introspection/FieldInfo.java @@ -240,7 +240,8 @@ public boolean equals(final Object obj) { return this.optional == other.optional && this.name.equals(other.name) && this.path.equals(other.path) - && this.fieldType.reference().equals(other.fieldType.reference()); + && this.fieldType.reference().equals(other.fieldType.reference()) + && this.fieldType.codec().equals(other.fieldType.codec()); } /** diff --git a/aether-datafixers-schema-tools/src/test/java/de/splatgames/aether/datafixers/schematools/introspection/FieldInfoTest.java b/aether-datafixers-schema-tools/src/test/java/de/splatgames/aether/datafixers/schematools/introspection/FieldInfoTest.java index e1bb719..5965d0f 100644 --- a/aether-datafixers-schema-tools/src/test/java/de/splatgames/aether/datafixers/schematools/introspection/FieldInfoTest.java +++ b/aether-datafixers-schema-tools/src/test/java/de/splatgames/aether/datafixers/schematools/introspection/FieldInfoTest.java @@ -22,6 +22,7 @@ package de.splatgames.aether.datafixers.schematools.introspection; +import de.splatgames.aether.datafixers.api.codec.Codecs; import de.splatgames.aether.datafixers.api.type.Type; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; @@ -183,6 +184,26 @@ void equalsReturnsTrueForSameInstance() { assertThat(field).isEqualTo(field); } + + @Test + @DisplayName("equals returns false for different Type.codec") + void equalsReturnsFalseForDifferentTypeCodec() { + var falseCodecStringType = Type.primitive("string", Codecs.INT); + final FieldInfo field1 = FieldInfo.create("health", false, falseCodecStringType, "player.health"); + final FieldInfo field2 = FieldInfo.create("health", false, Type.STRING, "player.health"); + + assertThat(field1).isNotEqualTo(field2); + } + + @Test + @DisplayName("equals returns false for different Type.ref and Type.describe") + void equalsReturnsFalseForDifferentTypeDescribe() { + var falseNameStringType = Type.primitive("int", Codecs.STRING); + final FieldInfo field1 = FieldInfo.create("health", false, falseNameStringType, "player.health"); + final FieldInfo field2 = FieldInfo.create("health", false, Type.STRING, "player.health"); + + assertThat(field1).isNotEqualTo(field2); + } } @Nested