Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent ConfigValue equals and hashcode #772

Merged
merged 1 commit into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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