Skip to content

Commit

Permalink
Add negative test
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew4699 committed Oct 4, 2024
1 parent 1c179c4 commit 4c4eec3
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,26 @@ public void testConfigsCanBeCastedFromString() {
}
}

@Test
public void testInvalidCastThrowsException() {
// Bool not included because Boolean.valueOf turns non-boolean strings to false
List<PolarisConfiguration<?>> configs =
List.of(buildConfig("int", 12), buildConfig("long", 34L), buildConfig("double", 5.6D));

PolarisConfigurationStore store =
new PolarisConfigurationStore() {
@SuppressWarnings("unchecked")
@Override
public <T> T getConfiguration(PolarisCallContext ctx, String configName) {
return (T) "abc123";
}
};

for (PolarisConfiguration<?> c : configs) {
Assertions.assertThrows(NumberFormatException.class, () -> store.getConfiguration(null, c));
}
}

private static <T> PolarisConfiguration<T> buildConfig(String key, T defaultValue) {
return PolarisConfiguration.<T>builder()
.key(key)
Expand Down

0 comments on commit 4c4eec3

Please sign in to comment.