@ -198,22 +198,21 @@ public class MessageSourceAutoConfigurationTests {
. isEqualTo ( "bar" ) ) ) ;
. isEqualTo ( "bar" ) ) ) ;
}
}
@Configuration
@Test
@PropertySource ( "classpath:/switch-messages.properties" )
public void messageSourceDeclaredWithNonStandardNameDoesNotBreakAutoConfig ( ) {
protected static class Config {
this . contextRunner . withPropertyValues ( "spring.messages.basename:test/messages" )
. withUserConfiguration ( ConfigWithNonStandardMessageSourceBeanName . class )
. run ( ( context ) - > {
assertThat ( context . getMessage ( "foo" , null , Locale . US ) )
. isEqualTo ( "bar" ) ;
} ) ;
}
}
@Configuration
private static class CodeReturningMessageSource implements MessageSource {
protected static class CustomMessageSource {
@Bean
public MessageSource messageSource ( ) {
return new MessageSource ( ) {
@Override
@Override
public String getMessage ( String code , Object [ ] args ,
public String getMessage ( String code , Object [ ] args , String defaultMessage ,
String defaultMessage , Locale locale ) {
Locale locale ) {
return code ;
return code ;
}
}
@ -224,12 +223,35 @@ public class MessageSourceAutoConfigurationTests {
}
}
@Override
@Override
public String getMessage ( MessageSourceResolvable resolvable ,
public String getMessage ( MessageSourceResolvable resolvable , Locale locale )
Locale locale ) throws NoSuchMessageException {
throws NoSuchMessageException {
return resolvable . getCodes ( ) [ 0 ] ;
return resolvable . getCodes ( ) [ 0 ] ;
}
}
} ;
}
@Configuration
protected static class ConfigWithNonStandardMessageSourceBeanName {
@Bean
public MessageSource codeReturningMessageSource ( ) {
return new CodeReturningMessageSource ( ) ;
}
}
@Configuration
@PropertySource ( "classpath:/switch-messages.properties" )
protected static class Config {
}
@Configuration
protected static class CustomMessageSource {
@Bean
public MessageSource messageSource ( ) {
return new CodeReturningMessageSource ( ) ;
}
}
}
}