@ -16,11 +16,14 @@
package org.springframework.boot.bind ;
import java.util.ArrayList ;
import java.util.Collection ;
import java.util.Collections ;
import java.util.LinkedHashMap ;
import org.junit.Before ;
import org.junit.Test ;
import org.springframework.beans.PropertyValue ;
import org.springframework.core.env.CompositePropertySource ;
import org.springframework.core.env.MapPropertySource ;
import org.springframework.core.env.MutablePropertySources ;
@ -61,6 +64,26 @@ public class PropertySourcesPropertyValuesTests {
assertEquals ( 1 , propertyValues . getPropertyValues ( ) . length ) ;
}
@Test
public void testOrderPreserved ( ) {
LinkedHashMap < String , Object > map = new LinkedHashMap < String , Object > ( ) ;
map . put ( "one" , 1 ) ;
map . put ( "two" , 2 ) ;
map . put ( "three" , 3 ) ;
map . put ( "four" , 4 ) ;
map . put ( "five" , 5 ) ;
this . propertySources . addFirst ( new MapPropertySource ( "ordered" , map ) ) ;
PropertySourcesPropertyValues propertyValues = new PropertySourcesPropertyValues (
this . propertySources ) ;
PropertyValue [ ] values = propertyValues . getPropertyValues ( ) ;
assertEquals ( 6 , values . length ) ;
Collection < String > names = new ArrayList < String > ( ) ;
for ( PropertyValue value : values ) {
names . add ( value . getName ( ) ) ;
}
assertEquals ( "[one, two, three, four, five, name]" , names . toString ( ) ) ;
}
@Test
public void testNonEnumeratedValue ( ) {
PropertySourcesPropertyValues propertyValues = new PropertySourcesPropertyValues (