This commit is contained in:
Phillip Webb
2014-06-17 12:14:15 -07:00
parent b439d3522e
commit 25eb6fb81a
6 changed files with 54 additions and 55 deletions

View File

@@ -153,7 +153,8 @@ public class SpringApplicationContextLoader extends AbstractContextLoader {
.detectDefaultConfigurationClasses(declaringClass);
}
protected Map<String, Object> getEnvironmentProperties(MergedContextConfiguration config) {
protected Map<String, Object> getEnvironmentProperties(
MergedContextConfiguration config) {
Map<String, Object> properties = new LinkedHashMap<String, Object>();
// JMX bean names will clash if the same bean is used in multiple contexts
disableJmx(properties);
@@ -180,7 +181,7 @@ public class SpringApplicationContextLoader extends AbstractContextLoader {
// Instead of parsing the keys ourselves, we rely on standard handling
private Map<String, String> extractEnvironmentProperties(String[] values) {
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder();
for (String value : values) {
sb.append(value).append(LINE_SEPARATOR);
}
@@ -190,11 +191,12 @@ public class SpringApplicationContextLoader extends AbstractContextLoader {
props.load(new StringReader(content));
}
catch (IOException e) {
throw new IllegalStateException("Unexpected could not load properties from '"+content+"'", e);
throw new IllegalStateException("Unexpected could not load properties from '"
+ content + "'", e);
}
Map<String, String> properties = new HashMap<String, String>();
for (String name: props.stringPropertyNames()) {
for (String name : props.stringPropertyNames()) {
properties.put(name, props.getProperty(name));
}
return properties;

View File

@@ -16,18 +16,19 @@
package org.springframework.boot.test;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.util.Map;
import org.junit.Test;
import org.springframework.test.context.MergedContextConfiguration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
/**
* Tests for {@link SpringApplicationContextLoader}
*
*
* @author Stephane Nicoll
*/
public class SpringApplicationContextLoaderTests {
@@ -55,12 +56,10 @@ public class SpringApplicationContextLoaderTests {
assertKey(config, "anotherKey", "another=Value");
}
private Map<String, Object> getEnvironmentProperties(Class<?> testClass) {
MergedContextConfiguration configuration = mock(MergedContextConfiguration.class);
doReturn(testClass).when(configuration).getTestClass();
return loader.getEnvironmentProperties(configuration);
return this.loader.getEnvironmentProperties(configuration);
}
private void assertKey(Map<String, Object> actual, String key, Object value) {
@@ -68,16 +67,15 @@ public class SpringApplicationContextLoaderTests {
assertEquals(value, actual.get(key));
}
@IntegrationTest({"key=myValue", "anotherKey:anotherValue"})
@IntegrationTest({ "key=myValue", "anotherKey:anotherValue" })
static class SimpleConfig {
}
@IntegrationTest({"key=my=Value", "anotherKey:another:Value"})
@IntegrationTest({ "key=my=Value", "anotherKey:another:Value" })
static class SameSeparatorInValue {
}
@IntegrationTest({"key=my:Value", "anotherKey:another=Value"})
@IntegrationTest({ "key=my:Value", "anotherKey:another=Value" })
static class AnotherSeparatorInValue {
}