Skip to content

Commit

Permalink
Consistent ConfigValue equals and hashcode (#772)
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez authored Jun 30, 2022
1 parent bf945f5 commit 7f19530
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
13 changes: 8 additions & 5 deletions implementation/src/main/java/io/smallrye/config/ConfigValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<String, String> properties;

Expand Down

0 comments on commit 7f19530

Please sign in to comment.