Add support for = separator in EnvironmentTestUtils
This commit is contained in:
@@ -19,8 +19,10 @@ package org.springframework.boot.test;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
|
||||
/**
|
||||
@@ -30,15 +32,32 @@ import org.springframework.core.env.MapPropertySource;
|
||||
*/
|
||||
public abstract class EnvironmentTestUtils {
|
||||
|
||||
/**
|
||||
* Add additional (high priority) values to an {@link Environment} owned by an
|
||||
* {@link ApplicationContext}. Name-value pairs can be specified with colon (":") or
|
||||
* equals ("=") separators.
|
||||
*
|
||||
* @param context the context with an environment to modify
|
||||
* @param pairs the name:value pairs
|
||||
*/
|
||||
public static void addEnvironment(ConfigurableApplicationContext context,
|
||||
String... pairs) {
|
||||
addEnvironment(context.getEnvironment(), pairs);
|
||||
}
|
||||
|
||||
public static void addEnvironment(ConfigurableEnvironment environment, String... pairs) {
|
||||
/**
|
||||
* Add additional (high priority) values to an {@link Environment}. Name-value pairs
|
||||
* can be specified with colon (":") or equals ("=") separators.
|
||||
*
|
||||
* @param environment the environment to modify
|
||||
* @param pairs the name:value pairs
|
||||
*/
|
||||
public static void addEnvironment(ConfigurableEnvironment environment,
|
||||
String... pairs) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
for (String pair : pairs) {
|
||||
int index = pair.indexOf(":");
|
||||
index = index < 0 ? index = pair.indexOf("=") : index;
|
||||
String key = pair.substring(0, index > 0 ? index : pair.length());
|
||||
String value = index > 0 ? pair.substring(index + 1) : "";
|
||||
map.put(key.trim(), value.trim());
|
||||
|
||||
Reference in New Issue
Block a user