Skip to content
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
1 change: 1 addition & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion config-magic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- Don't run JUnit tests -->
<groups />
<groups/>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

/**
* If a configuration bean is created with mapped replacement values via
* {@link ConfigurationObjectFactory#buildWithReplacements(Class, java.util.Map)},
* {@link AugmentedConfigurationObjectFactory#buildWithReplacements(Class, java.util.Map)},
* this annotation designates a method which should present the provided Map.
* The map may not be changed and is not necessarily the same instance as the original.
* If a key is provided, the return is instead the value for that key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@

import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,9 @@ public static Map<String, String> getAll() {
public static Map<String, Map<String, String>> getAllBySource() {
return Collections.unmodifiableMap(RUNTIME_CONFIGS_BY_SOURCE);
}

public static void clear() {
RUNTIME_CONFIGS.clear();
RUNTIME_CONFIGS_BY_SOURCE.clear();
}
}
4 changes: 2 additions & 2 deletions config-magic/src/test/java/org/skife/config/TestArrays.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
@Category(ConfigMagicTests.class)
public class TestArrays {

private ConfigurationObjectFactory cof;
private AugmentedConfigurationObjectFactory cof;

@Before
public void setUp() {
cof = new ConfigurationObjectFactory(new Properties());
cof = new AugmentedConfigurationObjectFactory(new Properties());
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
@Category(ConfigMagicTests.class)
public class TestBadConfig {

ConfigurationObjectFactory c = null;
AugmentedConfigurationObjectFactory c = null;

@Before
public void setUp() {
this.c = new ConfigurationObjectFactory(new Properties());
this.c = new AugmentedConfigurationObjectFactory(new Properties());
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ public class TestCaseInsensitiveEnumCoercible {

@Test
public void testHappyPath() throws Exception {
final ConfigurationObjectFactory cof = new ConfigurationObjectFactory(Props.of("creamer", "half_and_half"));
final AugmentedConfigurationObjectFactory cof = new AugmentedConfigurationObjectFactory(Props.of("creamer", "half_and_half"));

final Coffee coffee = cof.build(Coffee.class);
assertThat(coffee.getCreamer(), equalTo(Creamer.HALF_AND_HALF));
}

@Test(expected = IllegalStateException.class)
public void testNoMatch() throws Exception {
final ConfigurationObjectFactory cof = new ConfigurationObjectFactory(Props.of("creamer", "goat_milk"));
final AugmentedConfigurationObjectFactory cof = new AugmentedConfigurationObjectFactory(Props.of("creamer", "goat_milk"));

final Coffee coffee = cof.build(Coffee.class);
fail("should have raised an illegal state exception");
}

@Test(expected = IllegalArgumentException.class)
public void testExactMatch() throws Exception {
final ConfigurationObjectFactory cof = new ConfigurationObjectFactory(Props.of("creamer", "whole_milk"));
final ConfigurationObjectFactory cof = new AugmentedConfigurationObjectFactory(Props.of("creamer", "whole_milk"));
cof.addCoercible(new ExactMatchEnumCoercible());

final Coffee coffee = cof.build(Coffee.class);
Expand Down
32 changes: 16 additions & 16 deletions config-magic/src/test/java/org/skife/config/TestClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,100 +30,100 @@ public class TestClasses {

@Test
public void testRawType() {
final WithRawType config = new ConfigurationObjectFactory(Props.of("theClazz", Object.class.getName())).build(WithRawType.class);
final WithRawType config = new AugmentedConfigurationObjectFactory(Props.of("theClazz", Object.class.getName())).build(WithRawType.class);

Assert.assertEquals(config.getTheClazz(), Object.class);
}

@Test(expected = IllegalArgumentException.class)
public void testRawTypeNotFound() {
new ConfigurationObjectFactory(Props.of("theClazz", "does.not.Exist")).build(WithRawType.class);
new AugmentedConfigurationObjectFactory(Props.of("theClazz", "does.not.Exist")).build(WithRawType.class);
}

@Test(expected = IllegalArgumentException.class)
public void testRawTypeIllegal() {
new ConfigurationObjectFactory(Props.of("theClazz", "not a class")).build(WithRawType.class);
new AugmentedConfigurationObjectFactory(Props.of("theClazz", "not a class")).build(WithRawType.class);
}

@Test
public void testRawTypeWithDefault() {
final WithRawTypeAndDefault config = new ConfigurationObjectFactory(new Properties()).build(WithRawTypeAndDefault.class);
final WithRawTypeAndDefault config = new AugmentedConfigurationObjectFactory(new Properties()).build(WithRawTypeAndDefault.class);

Assert.assertEquals(config.getTheClazz(), Object.class);
}

@Test
public void testRawTypeWithNullDefault() {
final WithRawType config = new ConfigurationObjectFactory(new Properties()).build(WithRawType.class);
final WithRawType config = new AugmentedConfigurationObjectFactory(new Properties()).build(WithRawType.class);

Assert.assertNull(config.getTheClazz());
}

@Test(expected = IllegalArgumentException.class)
public void testRawTypeWithNotFoundDefault() {
new ConfigurationObjectFactory(new Properties()).build(WithRawTypeAndUndefinedDefault.class);
new AugmentedConfigurationObjectFactory(new Properties()).build(WithRawTypeAndUndefinedDefault.class);
}

@Test(expected = IllegalArgumentException.class)
public void testRawTypeWithIllegalDefault() {
new ConfigurationObjectFactory(new Properties()).build(WithRawTypeAndIllegalDefault.class);
new AugmentedConfigurationObjectFactory(new Properties()).build(WithRawTypeAndIllegalDefault.class);
}

@Test
public void testUnspecifiedType() {
final WithUnspecifiedType config = new ConfigurationObjectFactory(Props.of("theClazz", Foo.class.getName())).build(WithUnspecifiedType.class);
final WithUnspecifiedType config = new AugmentedConfigurationObjectFactory(Props.of("theClazz", Foo.class.getName())).build(WithUnspecifiedType.class);

Assert.assertEquals(config.getTheClazz(), Foo.class);
}

@Test
public void testExtends() {
final WithExtends config = new ConfigurationObjectFactory(Props.of("theClazz", Foo.class.getName())).build(WithExtends.class);
final WithExtends config = new AugmentedConfigurationObjectFactory(Props.of("theClazz", Foo.class.getName())).build(WithExtends.class);

Assert.assertEquals(config.getTheClazz(), Foo.class);
}

@Test
public void testExtendsWithSubClass() {
final WithExtends config = new ConfigurationObjectFactory(Props.of("theClazz", FooSub.class.getName())).build(WithExtends.class);
final WithExtends config = new AugmentedConfigurationObjectFactory(Props.of("theClazz", FooSub.class.getName())).build(WithExtends.class);

Assert.assertEquals(config.getTheClazz(), FooSub.class);
}

@Test(expected = IllegalArgumentException.class)
public void testExtendsWithSuperClass() {
new ConfigurationObjectFactory(Props.of("theClazz", FooSuper.class.getName())).build(WithExtends.class);
new AugmentedConfigurationObjectFactory(Props.of("theClazz", FooSuper.class.getName())).build(WithExtends.class);
}

@Test(expected = IllegalArgumentException.class)
public void testExtendsWithUnrelatedClass() {
new ConfigurationObjectFactory(Props.of("theClazz", Properties.class.getName())).build(WithExtends.class);
new AugmentedConfigurationObjectFactory(Props.of("theClazz", Properties.class.getName())).build(WithExtends.class);
}

@Test
public void testNestedExtends() {
final WithNestedExtends config = new ConfigurationObjectFactory(Props.of("theClazz", FooList.class.getName())).build(WithNestedExtends.class);
final WithNestedExtends config = new AugmentedConfigurationObjectFactory(Props.of("theClazz", FooList.class.getName())).build(WithNestedExtends.class);

Assert.assertEquals(config.getTheClazz(), FooList.class);
}

@Test
public void testNestedExtendsWithSubClass() {
final WithNestedExtends config = new ConfigurationObjectFactory(Props.of("theClazz", FooSubList.class.getName())).build(WithNestedExtends.class);
final WithNestedExtends config = new AugmentedConfigurationObjectFactory(Props.of("theClazz", FooSubList.class.getName())).build(WithNestedExtends.class);

Assert.assertEquals(config.getTheClazz(), FooSubList.class);
}

@Test
public void testNestedExtendsWithSuperClass() {
final WithNestedExtends config = new ConfigurationObjectFactory(Props.of("theClazz", FooSuperList.class.getName())).build(WithNestedExtends.class);
final WithNestedExtends config = new AugmentedConfigurationObjectFactory(Props.of("theClazz", FooSuperList.class.getName())).build(WithNestedExtends.class);

Assert.assertEquals(config.getTheClazz(), FooSuperList.class);
}

@Test
public void testNestedExtendsWithUnrelatedClass() {
final WithNestedExtends config = new ConfigurationObjectFactory(Props.of("theClazz", StringList.class.getName())).build(WithNestedExtends.class);
final WithNestedExtends config = new AugmentedConfigurationObjectFactory(Props.of("theClazz", StringList.class.getName())).build(WithNestedExtends.class);

Assert.assertEquals(config.getTheClazz(), StringList.class);
}
Expand Down
4 changes: 2 additions & 2 deletions config-magic/src/test/java/org/skife/config/TestCoercion.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
@Category(ConfigMagicTests.class)
public class TestCoercion {

private ConfigurationObjectFactory c = null;
private AugmentedConfigurationObjectFactory c = null;

@Before
public void setUp() {
this.c = new ConfigurationObjectFactory(new Properties() {{
this.c = new AugmentedConfigurationObjectFactory(new Properties() {{
setProperty("the-url", "http://github.org/brianm/config-magic");
}});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
@Category(ConfigMagicTests.class)
public class TestCollections {

private ConfigurationObjectFactory cof;
private AugmentedConfigurationObjectFactory cof;

@Before
public void setUp() {
cof = new ConfigurationObjectFactory(new Properties());
cof = new AugmentedConfigurationObjectFactory(new Properties());
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class TestConfigurationObjectFactory {

@Test
public void testMultipleReplacements() throws Exception {
final ConfigurationObjectFactory c = new ConfigurationObjectFactory(new Properties() {{
final ConfigurationObjectFactory c = new AugmentedConfigurationObjectFactory(new Properties() {{
setProperty("another-option.a.1", "A1");
setProperty("another-option.a.2", "A2");
setProperty("another-option.b.1", "B1");
Expand Down Expand Up @@ -71,7 +71,7 @@ public void testMultipleReplacements() throws Exception {
public void testReplacement() throws Exception {
final Map<String, String> replacementsMap = new HashMap<String, String>();
replacementsMap.put("type", "first");
final ConfigurationObjectFactory c = new ConfigurationObjectFactory(new Properties() {{
final ConfigurationObjectFactory c = new AugmentedConfigurationObjectFactory(new Properties() {{
setProperty("option.first", "1st");
setProperty("option.second", "2nd");
}});
Expand All @@ -85,7 +85,7 @@ public void testReplacement() throws Exception {

@Test
public void testFoo() throws Exception {
final ConfigurationObjectFactory c = new ConfigurationObjectFactory(new Properties() {{
final ConfigurationObjectFactory c = new AugmentedConfigurationObjectFactory(new Properties() {{
setProperty("hello", "world");
setProperty("theValue", "value");
}});
Expand All @@ -95,7 +95,7 @@ public void testFoo() throws Exception {

@Test
public void testEnum() throws Exception {
final ConfigurationObjectFactory c = new ConfigurationObjectFactory(new Properties() {{
final ConfigurationObjectFactory c = new AugmentedConfigurationObjectFactory(new Properties() {{
setProperty("option.one", "1");
setProperty("option.two", "2");
}});
Expand All @@ -107,7 +107,7 @@ public void testEnum() throws Exception {

@Test
public void testMultiParameters() throws Exception {
final ConfigurationObjectFactory c = new ConfigurationObjectFactory(new Properties() {{
final ConfigurationObjectFactory c = new AugmentedConfigurationObjectFactory(new Properties() {{
setProperty("another-option.one.a", "1-x");
setProperty("another-option.two.b", "2-y");
}});
Expand All @@ -119,21 +119,21 @@ public void testMultiParameters() throws Exception {

@Test
public void testDefaultValue() throws Exception {
final ConfigurationObjectFactory c = new ConfigurationObjectFactory(new Properties());
final ConfigurationObjectFactory c = new AugmentedConfigurationObjectFactory(new Properties());
final Thing t = c.build(Thing.class);
assertEquals(t.getName(), "woof");
}

@Test
public void testDefaultViaImpl() throws Exception {
final ConfigurationObjectFactory c = new ConfigurationObjectFactory(new Properties());
final ConfigurationObjectFactory c = new AugmentedConfigurationObjectFactory(new Properties());
final Config2 config = c.build(Config2.class);
assertEquals(config.getOption(), "default");
}

@Test
public void testProvidedOverridesDefault() throws Exception {
final ConfigurationObjectFactory c = new ConfigurationObjectFactory(new Properties() {{
final ConfigurationObjectFactory c = new AugmentedConfigurationObjectFactory(new Properties() {{
setProperty("option", "provided");
}});

Expand All @@ -143,7 +143,7 @@ public void testProvidedOverridesDefault() throws Exception {

@Test
public void testMissingDefault() throws Exception {
final ConfigurationObjectFactory c = new ConfigurationObjectFactory(new Properties());
final ConfigurationObjectFactory c = new AugmentedConfigurationObjectFactory(new Properties());
try {
c.build(Config3.class);
fail("Expected exception due to missing value");
Expand All @@ -153,7 +153,7 @@ public void testMissingDefault() throws Exception {

@Test
public void testDetectsAbstractMethod() throws Exception {
final ConfigurationObjectFactory c = new ConfigurationObjectFactory(new Properties());
final ConfigurationObjectFactory c = new AugmentedConfigurationObjectFactory(new Properties());
try {
c.build(Config4.class);
fail("Expected exception due to abstract method without @Config annotation");
Expand All @@ -163,7 +163,7 @@ public void testDetectsAbstractMethod() throws Exception {

@Test
public void testTypes() {
final ConfigurationObjectFactory c = new ConfigurationObjectFactory(new Properties() {{
final ConfigurationObjectFactory c = new AugmentedConfigurationObjectFactory(new Properties() {{
setProperty("stringOption", "a string");
setProperty("booleanOption", "true");
setProperty("boxedBooleanOption", "true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class TestCustomCoercion {

@Test(expected = IllegalStateException.class)
public void testNoConverterConfig() {
final ConfigurationObjectFactory c = new ConfigurationObjectFactory(new Properties() {{
final ConfigurationObjectFactory c = new AugmentedConfigurationObjectFactory(new Properties() {{
setProperty("the-url", "http://github.org/brianm/config-magic");
}});

Expand All @@ -41,7 +41,7 @@ public void testNoConverterConfig() {

@Test
public void testWithConverterConfig() {
final ConfigurationObjectFactory c = new ConfigurationObjectFactory(new Properties() {{
final ConfigurationObjectFactory c = new AugmentedConfigurationObjectFactory(new Properties() {{
setProperty("the-url", "http://github.org/brianm/config-magic");
}});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
@Category(ConfigMagicTests.class)
public class TestDataAmount {

private ConfigurationObjectFactory cof;
private AugmentedConfigurationObjectFactory cof;

@Before
public void setUp() {
cof = new ConfigurationObjectFactory(new Properties());
cof = new AugmentedConfigurationObjectFactory(new Properties());
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
@Category(ConfigMagicTests.class)
public class TestDefaultNull {

private ConfigurationObjectFactory cof = null;
private AugmentedConfigurationObjectFactory cof = null;

@Before
public void setUp() {
cof = new ConfigurationObjectFactory(new Properties());
cof = new AugmentedConfigurationObjectFactory(new Properties());
}

@After
Expand Down
Loading