Skip to content

Commit

Permalink
Merge 9ee32ee into ddfdfc0
Browse files Browse the repository at this point in the history
  • Loading branch information
andreipet committed Jul 6, 2014
2 parents ddfdfc0 + 9ee32ee commit b9fe509
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Expand Up @@ -80,6 +80,10 @@ private boolean equals(Method a, Method b) {
private Object resolveProperty(Method method, Object... args) {
String key = expandKey(method);
String value = propertiesManager.getProperty(key);
if (value == null && !isFeatureDisabled(method, VARIABLE_EXPANSION)) {
String unexpandedKey = key(method);
value = propertiesManager.getProperty(unexpandedKey);
}
if (value == null)
return null;
Object result = convert(method, method.getReturnType(), format(method, expandVariables(method, value), args));
Expand Down
Expand Up @@ -131,4 +131,23 @@ public void testKeyExpansionFromAnotherKeyWithImportOverriding() {
assertNull("mypass2", cfg.password()); // expansion is disabled on method level
}

@Sources("classpath:org/aeonbits/owner/variableexpansion/KeyExpansionExample.xml")
public interface UseOfDefaultValueIfNotFound extends Config {

@DefaultValue("dev")
String env();

@Config.Key("servers.${env}.nonDefinedInSourceKey")
@Config.DefaultValue("wantedValue")
String undefinedPropInSource();

}

@Test
public void testKeyExpansionAndDefaultValue() {
UseOfDefaultValueIfNotFound cfg = ConfigFactory.create(UseOfDefaultValueIfNotFound.class);

assertEquals("dev", cfg.env());
assertEquals("wantedValue", cfg.undefinedPropInSource());
}
}

0 comments on commit b9fe509

Please sign in to comment.