Polish "Add ReloadableResourceBundleMessageSource support"
See gh-13377
This commit is contained in:
parent
22abe35f95
commit
11ac9bf6b5
|
@ -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 {
|
||||||
|
|
||||||
@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) {
|
||||||
|
this.contextRunner.withPropertyValues(propertyValues).run((context) -> {
|
||||||
MessageSource messageSource = context.getBean(MessageSource.class);
|
MessageSource messageSource = context.getBean(MessageSource.class);
|
||||||
if (messageSource instanceof DelegatingMessageSource) {
|
if (messageSource instanceof DelegatingMessageSource) {
|
||||||
messageSource = ((DelegatingMessageSource) messageSource)
|
messageSource = ((DelegatingMessageSource) messageSource)
|
||||||
.getParentMessageSource();
|
.getParentMessageSource();
|
||||||
}
|
}
|
||||||
return messageSource;
|
assertThat(messageSource).isInstanceOf(expectedInstance);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
|
|
Loading…
Reference in New Issue