diff --git a/implementation/src/main/java/io/smallrye/config/ConfigValue.java b/implementation/src/main/java/io/smallrye/config/ConfigValue.java index 804a8a2c6..a94a369a1 100644 --- a/implementation/src/main/java/io/smallrye/config/ConfigValue.java +++ b/implementation/src/main/java/io/smallrye/config/ConfigValue.java @@ -129,15 +129,18 @@ public boolean equals(final Object o) { return false; } final ConfigValue that = (ConfigValue) o; - return name.equals(that.name) && - value.equals(that.value) && - rawValue.equals(that.rawValue) && - configSourceName.equals(that.configSourceName); + return configSourceOrdinal == that.configSourceOrdinal && + configSourcePosition == that.configSourcePosition && + name.equals(that.name) && + Objects.equals(value, that.value) && + Objects.equals(rawValue, that.rawValue) && + Objects.equals(profile, that.profile) && + Objects.equals(configSourceName, that.configSourceName); } @Override public int hashCode() { - return Objects.hash(name, value, configSourceName); + return Objects.hash(name, value, rawValue, profile, configSourceName, configSourceOrdinal, configSourcePosition); } @Override diff --git a/implementation/src/test/java/io/smallrye/config/ConfigValueTest.java b/implementation/src/test/java/io/smallrye/config/ConfigValueTest.java index eefd68b65..eb4f54559 100644 --- a/implementation/src/test/java/io/smallrye/config/ConfigValueTest.java +++ b/implementation/src/test/java/io/smallrye/config/ConfigValueTest.java @@ -1,6 +1,7 @@ package io.smallrye.config; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import java.util.HashMap; import java.util.Map; @@ -28,6 +29,21 @@ void configValue() { assertEquals(1000, configValue.getSourceOrdinal()); } + @Test + void configValueEquals() { + ConfigValue o1 = io.smallrye.config.ConfigValue.builder().withName("my.prop").build(); + ConfigValue o2 = io.smallrye.config.ConfigValue.builder().withName("my.prop").build(); + assertEquals(o2, o1); + + o1 = io.smallrye.config.ConfigValue.builder().withName("my.prop").withValue("value").build(); + o2 = io.smallrye.config.ConfigValue.builder().withName("my.prop").build(); + assertNotEquals(o2, o1); + + o1 = io.smallrye.config.ConfigValue.builder().withName("my.prop").withLineNumber(1).build(); + o2 = io.smallrye.config.ConfigValue.builder().withName("my.prop").withLineNumber(2).build(); + assertEquals(o2, o1); + } + public static class ConfigValueConfigSource implements ConfigSource { private final Map properties;