11/* 
2-  * Copyright 2002-2015  the original author or authors. 
2+  * Copyright 2002-2016  the original author or authors. 
33 * 
44 * Licensed under the Apache License, Version 2.0 (the "License"); 
55 * you may not use this file except in compliance with the License. 
2727
2828import  org .apache .commons .logging .Log ;
2929import  org .apache .commons .logging .LogFactory ;
30- 
3130import  org .springframework .context .ConfigurableApplicationContext ;
3231import  org .springframework .core .env .ConfigurableEnvironment ;
3332import  org .springframework .core .env .Environment ;
@@ -174,7 +173,7 @@ private static String[] mergeProperties(List<TestPropertySourceAttributes> attri
174173	 * @throws IllegalStateException if an error occurs while processing a properties file 
175174	 */ 
176175	public  static  void  addPropertiesFilesToEnvironment (ConfigurableApplicationContext  context ,
177- 			String []  locations ) {
176+ 			String ...  locations ) {
178177		Assert .notNull (context , "context must not be null" );
179178		Assert .notNull (locations , "locations must not be null" );
180179		try  {
@@ -204,7 +203,7 @@ public static void addPropertiesFilesToEnvironment(ConfigurableApplicationContex
204203	 * @see #addInlinedPropertiesToEnvironment(ConfigurableEnvironment, String[]) 
205204	 */ 
206205	public  static  void  addInlinedPropertiesToEnvironment (ConfigurableApplicationContext  context ,
207- 			String []  inlinedProperties ) {
206+ 			String ...  inlinedProperties ) {
208207		Assert .notNull (context , "context must not be null" );
209208		Assert .notNull (inlinedProperties , "inlinedProperties must not be null" );
210209		addInlinedPropertiesToEnvironment (context .getEnvironment (), inlinedProperties );
@@ -226,17 +225,21 @@ public static void addInlinedPropertiesToEnvironment(ConfigurableApplicationCont
226225	 * @see TestPropertySource#properties 
227226	 * @see #convertInlinedPropertiesToMap 
228227	 */ 
229- 	public  static  void  addInlinedPropertiesToEnvironment (ConfigurableEnvironment  environment , String []  inlinedProperties ) {
228+ 	public  static  void  addInlinedPropertiesToEnvironment (ConfigurableEnvironment  environment , String ...  inlinedProperties ) {
230229		Assert .notNull (environment , "environment must not be null" );
231230		Assert .notNull (inlinedProperties , "inlinedProperties must not be null" );
232231		if  (!ObjectUtils .isEmpty (inlinedProperties )) {
233232			if  (logger .isDebugEnabled ()) {
234233				logger .debug ("Adding inlined properties to environment: " 
235234						+ ObjectUtils .nullSafeToString (inlinedProperties ));
236235			}
237- 			MapPropertySource  ps  = new  MapPropertySource (INLINED_PROPERTIES_PROPERTY_SOURCE_NAME ,
238- 				convertInlinedPropertiesToMap (inlinedProperties ));
239- 			environment .getPropertySources ().addFirst (ps );
236+ 			MapPropertySource  ps  = (MapPropertySource ) environment .getPropertySources ().get (INLINED_PROPERTIES_PROPERTY_SOURCE_NAME );
237+ 			if  (ps  == null ) {
238+ 				ps  = new  MapPropertySource (INLINED_PROPERTIES_PROPERTY_SOURCE_NAME ,
239+ 						new  LinkedHashMap <String , Object >());
240+ 				environment .getPropertySources ().addFirst (ps );
241+ 			}
242+ 			ps .getSource ().putAll (convertInlinedPropertiesToMap (inlinedProperties ));
240243		}
241244	}
242245
@@ -257,7 +260,7 @@ public static void addInlinedPropertiesToEnvironment(ConfigurableEnvironment env
257260	 * a given inlined property contains multiple key-value pairs 
258261	 * @see #addInlinedPropertiesToEnvironment(ConfigurableEnvironment, String[]) 
259262	 */ 
260- 	public  static  Map <String , Object > convertInlinedPropertiesToMap (String []  inlinedProperties ) {
263+ 	public  static  Map <String , Object > convertInlinedPropertiesToMap (String ...  inlinedProperties ) {
261264		Assert .notNull (inlinedProperties , "inlinedProperties must not be null" );
262265		Map <String , Object > map  = new  LinkedHashMap <String , Object >();
263266
0 commit comments