Skip to content

Commit e188ad8

Browse files
authored
Merge pull request #14755 from robertoschwald/issue-11795_testcase
Test-Case for #14753
2 parents ba448f1 + 341ea74 commit e188ad8

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

grails-core/src/test/groovy/org/grails/spring/context/ResourceBundleMessageSourceSpec.groovy

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ class ResourceBundleMessageSourceSpec extends Specification {
3030
void setup(){
3131
messages = new TestResource('messages.properties','''\
3232
foo=bar
33+
shared.message=Messages Message
3334
'''.stripIndent().getBytes('UTF-8'))
3435

3536
other = new TestResource('other.properties','''\
3637
bar=foo
38+
shared.message=Other Message
3739
'''.stripIndent().getBytes('UTF-8'))
3840
}
3941

@@ -49,11 +51,27 @@ class ResourceBundleMessageSourceSpec extends Specification {
4951
messageSource.setBasenames('messages','other')
5052
def locale = Locale.default
5153
expect:
52-
messageSource.getBundleCodes(locale,'messages') == (['foo'] as Set)
53-
messageSource.getBundleCodes(locale,'other') == (['bar'] as Set)
54-
messageSource.getBundleCodes(locale,'messages','other') == (['foo','bar'] as Set)
54+
messageSource.getBundleCodes(locale,'messages') == (['foo', 'shared.message'] as Set)
55+
messageSource.getBundleCodes(locale,'other') == (['bar', 'shared.message'] as Set)
56+
messageSource.getBundleCodes(locale,'messages','other') == (['foo','bar', 'shared.message'] as Set)
5557
}
5658

59+
void 'Check method to verify ResourceBundle ordering prioritizes application over plugin messages'(){
60+
given:
61+
def messageSource = new ReloadableResourceBundleMessageSource(
62+
resourceLoader: new DefaultResourceLoader(){
63+
Resource getResourceByPath(String path){
64+
path.startsWith('messages') ? messages:other
65+
}
66+
}
67+
)
68+
messageSource.setBasenames('other', 'messages')
69+
def locale = Locale.default
70+
expect: "other messages override plugin messages"
71+
messageSource.getMessage('shared.message', null, locale) == 'Other Message'
72+
messageSource.getMessage('foo', null, locale) == 'bar'
73+
}
74+
5775
class TestResource extends ByteArrayResource{
5876
String filename
5977

0 commit comments

Comments
 (0)