diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/MessageSourceAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/MessageSourceAutoConfigurationTests.java index 93a088e6bc5..5683d5f2e6d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/MessageSourceAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/MessageSourceAutoConfigurationTests.java @@ -184,7 +184,7 @@ public class MessageSourceAutoConfigurationTests { @Test public void existingMessageSourceIsPreferred() { - this.contextRunner.withUserConfiguration(CustomMessageSource.class) + this.contextRunner.withUserConfiguration(CustomMessageSourceConfiguration.class) .run((context) -> assertThat(context.getMessage("foo", null, null, null)) .isEqualTo("foo")); } @@ -199,16 +199,42 @@ public class MessageSourceAutoConfigurationTests { } @Test - public void messageSourceDeclaredWithNonStandardNameDoesNotBreakAutoConfig() { + public void messageSourceWithNonStandardBeanNameIsIgnored() { this.contextRunner.withPropertyValues("spring.messages.basename:test/messages") - .withUserConfiguration(ConfigWithNonStandardMessageSourceBeanName.class) + .withUserConfiguration(CustomBeanNameMessageSourceConfiguration.class) .run((context) -> { assertThat(context.getMessage("foo", null, Locale.US)) .isEqualTo("bar"); }); } - private static class CodeReturningMessageSource implements MessageSource { + @Configuration + @PropertySource("classpath:/switch-messages.properties") + protected static class Config { + + } + + @Configuration + protected static class CustomMessageSourceConfiguration { + + @Bean + public MessageSource messageSource() { + return new TestMessageSource(); + } + + } + + @Configuration + protected static class CustomBeanNameMessageSourceConfiguration { + + @Bean + public MessageSource codeReturningMessageSource() { + return new TestMessageSource(); + } + + } + + private static class TestMessageSource implements MessageSource { @Override public String getMessage(String code, Object[] args, String defaultMessage, @@ -230,30 +256,4 @@ public class MessageSourceAutoConfigurationTests { } - @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(); - } - - } - }