Skip to content

Commit 666fc3f

Browse files
committed
Added test for retrieving bundle codes per messagebundle.
1 parent f3debfb commit 666fc3f

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.grails.spring.context
2+
3+
import org.grails.spring.context.support.ReloadableResourceBundleMessageSource
4+
import org.springframework.core.io.FileSystemResourceLoader
5+
import org.springframework.core.io.Resource
6+
import spock.lang.Specification
7+
8+
class ResourceBundleMessageSourceSpec extends Specification {
9+
File resourceFolder
10+
11+
void setup(){
12+
resourceFolder = new File(System.getProperty('java.io.tmpdir'),'resources')
13+
resourceFolder.mkdirs()
14+
def messages = new File(resourceFolder,'messages.properties')
15+
messages.text = '''\
16+
foo=bar
17+
'''.stripIndent()
18+
def other = new File(resourceFolder,'other.properties')
19+
other.text = '''\
20+
bar=foo
21+
'''.stripIndent()
22+
}
23+
24+
void cleanup(){
25+
resourceFolder.deleteDir()
26+
}
27+
28+
29+
void 'Check method to retrieve bundle codes per messagebundle'(){
30+
given:
31+
def messageSource = new ReloadableResourceBundleMessageSource(
32+
resourceLoader: new TempResourceLoader(resourceFolder:resourceFolder)
33+
)
34+
messageSource.setBasenames('messages','other')
35+
def locale = Locale.default
36+
expect:
37+
messageSource.getBundleCodes(locale,'messages') == ['foo']
38+
messageSource.getBundleCodes(locale,'other') == ['bar']
39+
messageSource.getBundleCodes(locale,'messages','other') == ['foo','bar']
40+
}
41+
42+
}
43+
44+
class TempResourceLoader extends FileSystemResourceLoader{
45+
File resourceFolder
46+
47+
@Override
48+
protected Resource getResourceByPath(String path) {
49+
path = new File(resourceFolder,path).absolutePath
50+
return super.getResourceByPath(path)
51+
}
52+
}
53+

0 commit comments

Comments
 (0)