Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
56977c03
Commit
56977c03
authored
Oct 16, 2015
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.2.x'
parents
f8cffd74
c236db04
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
0 deletions
+64
-0
MessageSourceAutoConfigurationTests.java
...ot/autoconfigure/MessageSourceAutoConfigurationTests.java
+64
-0
No files found.
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/MessageSourceAutoConfigurationTests.java
View file @
56977c03
...
...
@@ -22,7 +22,12 @@ import org.junit.After;
import
org.junit.Ignore
;
import
org.junit.Test
;
import
org.springframework.boot.test.EnvironmentTestUtils
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.MessageSource
;
import
org.springframework.context.MessageSourceResolvable
;
import
org.springframework.context.NoSuchMessageException
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.PropertySource
;
...
...
@@ -112,6 +117,36 @@ public class MessageSourceAutoConfigurationTests {
.
isFallbackToSystemLocale
());
}
@Test
public
void
existingMessageSourceIsPreferred
()
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
this
.
context
.
register
(
CustomMessageSource
.
class
,
MessageSourceAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
assertEquals
(
"foo"
,
this
.
context
.
getMessage
(
"foo"
,
null
,
null
,
null
));
}
@Test
public
void
existingMessageSourceInParentIsIgnored
()
{
ConfigurableApplicationContext
parent
=
new
AnnotationConfigApplicationContext
();
parent
.
refresh
();
try
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
this
.
context
.
setParent
(
parent
);
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"spring.messages.basename:test/messages"
);
this
.
context
.
register
(
MessageSourceAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
assertEquals
(
"bar"
,
this
.
context
.
getMessage
(
"foo"
,
null
,
"Foo message"
,
Locale
.
UK
));
}
finally
{
parent
.
close
();
}
}
private
void
load
(
String
...
environment
)
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
environment
);
...
...
@@ -126,4 +161,33 @@ public class MessageSourceAutoConfigurationTests {
}
@Configuration
protected
static
class
CustomMessageSource
{
@Bean
public
MessageSource
messageSource
()
{
return
new
MessageSource
()
{
@Override
public
String
getMessage
(
String
code
,
Object
[]
args
,
String
defaultMessage
,
Locale
locale
)
{
return
code
;
}
@Override
public
String
getMessage
(
String
code
,
Object
[]
args
,
Locale
locale
)
throws
NoSuchMessageException
{
return
code
;
}
@Override
public
String
getMessage
(
MessageSourceResolvable
resolvable
,
Locale
locale
)
throws
NoSuchMessageException
{
return
resolvable
.
getCodes
()[
0
];
}
};
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment