@ -644,24 +644,36 @@ class ConfigurationPropertiesTests {
@@ -644,24 +644,36 @@ class ConfigurationPropertiesTests {
@Test
void loadShouldUseConverterBean ( ) {
prepareConverterContext ( ConverterConfiguration . class , PersonProperties . class ) ;
prepareConverterContext ( Person ConverterConfiguration. class , PersonProperties . class ) ;
Person person = this . context . getBean ( PersonProperties . class ) . getPerson ( ) ;
assertThat ( person . firstName ) . isEqualTo ( "John" ) ;
assertThat ( person . lastName ) . isEqualTo ( "Smith" ) ;
}
@Test
void loadWhenBeanFactoryConversionServiceAndConverterBean ( ) {
void loadWhenBeanFactoryConversionServiceAndConverterBeanCanUseBeanFactoryConverter ( ) {
DefaultConversionService conversionService = new DefaultConversionService ( ) ;
conversionService . addConverter ( new AlienConverter ( ) ) ;
this . context . getBeanFactory ( ) . setConversionService ( conversionService ) ;
load ( new Class < ? > [ ] { ConverterConfiguration . class , PersonAndAlienProperties . class } , "test.person=John Smith" ,
"test.alien=Alf Tanner" ) ;
load ( new Class < ? > [ ] { Person ConverterConfiguration. class , PersonAndAlienProperties . class } ,
"test.person=John Smith" , "test. alien=Alf Tanner" ) ;
PersonAndAlienProperties properties = this . context . getBean ( PersonAndAlienProperties . class ) ;
assertThat ( properties . getPerson ( ) . firstName ) . isEqualTo ( "John" ) ;
assertThat ( properties . getPerson ( ) . lastName ) . isEqualTo ( "Smith" ) ;
assertThat ( properties . getAlien ( ) . firstName ) . isEqualTo ( "Alf" ) ;
assertThat ( properties . getAlien ( ) . lastName ) . isEqualTo ( "Tanner" ) ;
assertThat ( properties . getAlien ( ) . name ) . isEqualTo ( "rennaT flA" ) ;
}
@Test
void loadWhenBeanFactoryConversionServiceAndConverterBeanCanUseConverterBean ( ) {
DefaultConversionService conversionService = new DefaultConversionService ( ) ;
conversionService . addConverter ( new PersonConverter ( ) ) ;
this . context . getBeanFactory ( ) . setConversionService ( conversionService ) ;
load ( new Class < ? > [ ] { AlienConverterConfiguration . class , PersonAndAlienProperties . class } ,
"test.person=John Smith" , "test.alien=Alf Tanner" ) ;
PersonAndAlienProperties properties = this . context . getBean ( PersonAndAlienProperties . class ) ;
assertThat ( properties . getPerson ( ) . firstName ) . isEqualTo ( "John" ) ;
assertThat ( properties . getPerson ( ) . lastName ) . isEqualTo ( "Smith" ) ;
assertThat ( properties . getAlien ( ) . name ) . isEqualTo ( "rennaT flA" ) ;
}
@Test
@ -1440,7 +1452,7 @@ class ConfigurationPropertiesTests {
@@ -1440,7 +1452,7 @@ class ConfigurationPropertiesTests {
}
@Configuration ( proxyBeanMethods = false )
static class ConverterConfiguration {
static class Person ConverterConfiguration {
@Bean
@ConfigurationPropertiesBinding
@ -1450,6 +1462,17 @@ class ConfigurationPropertiesTests {
@@ -1450,6 +1462,17 @@ class ConfigurationPropertiesTests {
}
@Configuration ( proxyBeanMethods = false )
static class AlienConverterConfiguration {
@Bean
@ConfigurationPropertiesBinding
Converter < String , Alien > alienConverter ( ) {
return new AlienConverter ( ) ;
}
}
@Configuration ( proxyBeanMethods = false )
static class NonQualifiedConverterConfiguration {
@ -2398,8 +2421,7 @@ class ConfigurationPropertiesTests {
@@ -2398,8 +2421,7 @@ class ConfigurationPropertiesTests {
@Override
public Alien convert ( String source ) {
String [ ] content = StringUtils . split ( source , " " ) ;
return new Alien ( content [ 0 ] , content [ 1 ] ) ;
return new Alien ( new StringBuilder ( source ) . reverse ( ) . toString ( ) ) ;
}
}
@ -2467,21 +2489,14 @@ class ConfigurationPropertiesTests {
@@ -2467,21 +2489,14 @@ class ConfigurationPropertiesTests {
static class Alien {
private final String firstName ;
private final String lastName ;
Alien ( String firstName , String lastName ) {
this . firstName = firstName ;
this . lastName = lastName ;
}
private final String name ;
String getFirstName ( ) {
return this . firstN ame;
Alien ( String name ) {
this . name = name ;
}
String getLast Name ( ) {
return this . lastN ame;
String getName ( ) {
return this . name ;
}
}