Skip to content

Commit

Permalink
fixed bug: imported properties should have higher priority than @sources
Browse files Browse the repository at this point in the history
  • Loading branch information
Luigi R. Viggiano committed Jun 25, 2013
1 parent 73ee28a commit 3178f1a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/org/aeonbits/owner/PropertiesLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ abstract class PropertiesLoader {
static Properties load(Class<? extends Config> clazz, Map<?, ?>... imports) {
try {
Properties props = defaults(clazz);
merge(props, reverse(imports));
ConfigURLStreamHandler handler = new ConfigURLStreamHandler(clazz.getClassLoader(), expander);
Properties loadedFromFile = doLoad(clazz, handler);
merge(props, loadedFromFile);
merge(props, reverse(imports));
return props;
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/org/aeonbits/owner/ImportConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,27 @@ public void testImportOrder() {
assertEquals("lime", cfg.bar()); // p1 prevails, so this is lime and not grapefruit
assertEquals("blackberry", cfg.baz());
}

interface ImportedPropertiesHaveHigherPriority extends Config {
Integer minAge();
}

@Test
public void testImportedPropertiesShouldOverrideSources() {
ImportedPropertiesHaveHigherPriority cfg = ConfigFactory.create(ImportedPropertiesHaveHigherPriority.class);
assertEquals(Integer.valueOf(18), cfg.minAge());

ImportedPropertiesHaveHigherPriority cfg2 = ConfigFactory.create(ImportedPropertiesHaveHigherPriority.class,
new Properties() {{
setProperty("minAge", "21");
}},

new Properties() {{
setProperty("minAge", "22");
}}

);

assertEquals(Integer.valueOf(21), cfg2.minAge());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
minAge=18

0 comments on commit 3178f1a

Please sign in to comment.