Skip to content

Commit

Permalink
unwrap config to SmallRyeConfig instead of cast
Browse files Browse the repository at this point in the history
unwrap to SmallRyeConfig in other places too

unwrap over cast to SmallRyeConfig in test
  • Loading branch information
craig-day committed Jan 16, 2023
1 parent 08cfa57 commit 31d5fe8
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public T create(CreationalContext<T> context) {
} else {
Optional<T> optionalValue = (Optional<T>) getConfig().getOptionalValue(key, annotatedTypeClass);
return optionalValue.orElseGet(
() -> (T) ((SmallRyeConfig) getConfig()).convert(defaultValue, annotatedTypeClass));
() -> (T) getConfig().unwrap(SmallRyeConfig.class).convert(defaultValue, annotatedTypeClass));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public T create(final CreationalContext<T> creationalContext) {
}
}

SmallRyeConfig config = (SmallRyeConfig) ConfigProvider.getConfig(getContextClassLoader());
SmallRyeConfig config = ConfigProvider.getConfig(getContextClassLoader()).unwrap(SmallRyeConfig.class);
return config.getConfigMapping(getBeanClass(), prefix);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private static <T> Class<T> rawTypeOf(final Type type) {

/**
* Indicates whether the given type is a type of Map or is a Supplier or Optional of Map.
*
*
* @param type the type to check
* @return {@code true} if the given type is a type of Map or is a Supplier or Optional of Map,
* {@code false} otherwise.
Expand Down Expand Up @@ -408,7 +408,7 @@ public Map<K, V> convert(String value) throws IllegalArgumentException, NullPoin
*/
private static <K, V> Map<K, V> getValues(String name, Config config, Converter<K> keyConverter,
Converter<V> valueConverter) {
return SecretKeys.doUnlocked(() -> ((SmallRyeConfig) config).getValuesAsMap(name, keyConverter, valueConverter));
return SecretKeys.doUnlocked(() -> config.unwrap(SmallRyeConfig.class).getValuesAsMap(name, keyConverter, valueConverter));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public T create(final CreationalContext<T> creationalContext) {
}
}

SmallRyeConfig config = (SmallRyeConfig) ConfigProvider.getConfig(getContextClassLoader());
SmallRyeConfig config = ConfigProvider.getConfig(getContextClassLoader()).unwrap(SmallRyeConfig.class);
return config.getConfigMapping(getBeanClass(), prefix);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class ServerMapping {
public static Server getServer() {
SmallRyeConfig config = (SmallRyeConfig) ConfigProvider.getConfig();
SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
return config.getConfigMapping(Server.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class ConfigSourcePropertySubstitutionTest {
@Test
void interceptor() {
SmallRyeConfig config = (SmallRyeConfig) buildConfig("my.prop", "${prop.replace}", "prop.replace", "1234");
SmallRyeConfig config = buildConfig("my.prop", "${prop.replace}", "prop.replace", "1234").unwrap(SmallRyeConfig.class);

final String value = config.getValue("my.prop", String.class);
Assertions.assertEquals("1234", value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class ConfigValuePropertiesConfigSourceTest {
@Test
void interceptor() throws Exception {
SmallRyeConfig config = (SmallRyeConfig) buildConfig();
SmallRyeConfig config = buildConfig().unwrap(SmallRyeConfig.class);

assertEquals("1", config.getValue("my.prop", String.class));
assertEquals("20", config.getValue("my.prop.20", String.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void characterConverter() {
@Test
void explicitConverter() {
// setup
SmallRyeConfig config = (SmallRyeConfig) buildConfig("my.prop", "1234");// sanity check
SmallRyeConfig config = buildConfig("my.prop", "1234").unwrap(SmallRyeConfig.class);// sanity check
final Converter<Integer> customConverter = new Converter<Integer>() {
public Integer convert(final String value) {
return Integer.valueOf(Integer.parseInt(value) * 2);
Expand Down Expand Up @@ -109,7 +109,7 @@ void UUID() {
assertEquals(uuidUUIDTruth, config.getValue("uuid.shouting", UUID.class), "Uppercase UUID incorrectly converted");

// Check UUIDs work fine in arrays
ArrayList<UUID> values = ((SmallRyeConfig) config).getValues("uuid.multiple", UUID.class, ArrayList::new);
ArrayList<UUID> values = config.unwrap(SmallRyeConfig.class).getValues("uuid.multiple", UUID.class, ArrayList::new);
assertEquals(uuidUUIDTruth, values.get(0), "Unexpected list item in UUID config");
assertEquals(secondUuidUUIDTruth, values.get(1), "Unexpected list item in UUID config");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ void setUp() {
Properties properties = new Properties();
properties.put("my.pets", "snake,dog,cat,cat");

config = (SmallRyeConfig) SmallRyeConfigProviderResolver.instance().getBuilder()
config = SmallRyeConfigProviderResolver.instance().getBuilder()
.withSources(new PropertiesConfigSource(properties, "my properties"))
.build();
.build()
.unwrap(SmallRyeConfig.class);
}

@Test
Expand Down

0 comments on commit 31d5fe8

Please sign in to comment.