Commit 11ac9bf6 authored by Phillip Webb's avatar Phillip Webb

Polish "Add ReloadableResourceBundleMessageSource support"

See gh-13377
parent 22abe35f
...@@ -21,7 +21,6 @@ import java.util.Locale; ...@@ -21,7 +21,6 @@ import java.util.Locale;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.BeansException;
import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext; import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
...@@ -226,39 +225,34 @@ public class MessageSourceAutoConfigurationTests { ...@@ -226,39 +225,34 @@ public class MessageSourceAutoConfigurationTests {
@Test @Test
public void testDefaultReloadableValueMessageSource() { public void testDefaultReloadableValueMessageSource() {
this.contextRunner.withPropertyValues("spring.messages.basename:test/messages") testReloadableMessageSource(ResourceBundleMessageSource.class,
.run((context) -> assertThat(getDeclaredMessageSource(context)) "spring.messages.basename:test/messages");
.isInstanceOf(ResourceBundleMessageSource.class));
} }
@Test @Test
public void testNotReloadableMessageSource() { public void testNotReloadableMessageSource() {
this.contextRunner testReloadableMessageSource(ResourceBundleMessageSource.class,
.withPropertyValues("spring.messages.basename:test/messages", "spring.messages.basename:test/messages",
"spring.messages.reloadable:false") "spring.messages.reloadable:false");
.run((context) -> assertThat(getDeclaredMessageSource(context))
.isInstanceOf(ResourceBundleMessageSource.class));
} }
@Test @Test
public void testReloadableMessageSource() { public void testReloadableMessageSource() {
this.contextRunner.withPropertyValues("spring.messages.basename:test/messages", testReloadableMessageSource(ReloadableResourceBundleMessageSource.class,
"spring.messages.reloadable:true").run((context) -> { "spring.messages.basename:test/messages",
assertThat(getDeclaredMessageSource(context)) "spring.messages.reloadable:true");
.isInstanceOf(ReloadableResourceBundleMessageSource.class);
assertThat(context.getMessage("foo", null, "Foo message", Locale.UK))
.isEqualTo("bar");
});
} }
private MessageSource getDeclaredMessageSource(AssertableApplicationContext context) private void testReloadableMessageSource(Class<?> expectedInstance,
throws BeansException { String... propertyValues) {
MessageSource messageSource = context.getBean(MessageSource.class); this.contextRunner.withPropertyValues(propertyValues).run((context) -> {
if (messageSource instanceof DelegatingMessageSource) { MessageSource messageSource = context.getBean(MessageSource.class);
messageSource = ((DelegatingMessageSource) messageSource) if (messageSource instanceof DelegatingMessageSource) {
.getParentMessageSource(); messageSource = ((DelegatingMessageSource) messageSource)
} .getParentMessageSource();
return messageSource; }
assertThat(messageSource).isInstanceOf(expectedInstance);
});
} }
@Configuration @Configuration
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment