home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Groovy example source code file (ResourceBundleTest.groovy)

This example Groovy source code file (ResourceBundleTest.groovy) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

classloader, classloader, groovytestcase, groovytestcase, resourcebundle, resourcebundle, resourcebundletest, resourcebundletest, util

The Groovy ResourceBundleTest.groovy source code

package groovy.util;

import java.util.ResourceBundle;

public class ResourceBundleTest extends GroovyTestCase {
    public void testNoClassLoaderNoLocale() {
        def results = []
        // run test twice, call site optimizations result in call stack differences
        2.times {
            ResourceBundle rb = ResourceBundle.getBundle("groovy.util.i18n")
            results << rb
            assert rb.getString('upvote') == '+1'
        }
        assert results.size() == 2
    }

    public void testWithLocale() {
        def results = []
        // run test twice, call site optimizations result in call stack differences
        2.times {
            ResourceBundle rb = ResourceBundle.getBundle("groovy.util.i18n", Locale.ENGLISH)
            results << rb
            println "en"
            println "'${rb.getString('yes')}'"
            println "'${rb.getString('upvote')}'"
            assert rb.getString('yes') == 'yes'
            assert rb.getString('upvote') == '+1'
            rb = ResourceBundle.getBundle("groovy.util.i18n", Locale.FRENCH)
            results << rb
            println "fr"
            println "'${rb.getString('yes')}'"
            println "'${rb.getString('upvote')}'"
            assert rb.getString('yes') == 'oui'
            assert rb.getString('upvote') == '+1'
        }
        assert results.size() == 4
    }

    public void testWithClassLoader() {
        def results = []
        ClassLoader cl = this.class.classLoader
        // run test twice, call site optimizations result in call stack differences
        2.times {
            ResourceBundle rb = ResourceBundle.getBundle("groovy.util.i18n", Locale.ENGLISH, cl)
            results << rb
            println "en"
            println "'${rb.getString('yes')}'"
            println "'${rb.getString('upvote')}'"
            assert rb.getString('yes') == 'yes'
            assert rb.getString('upvote') == '+1'
            rb = ResourceBundle.getBundle("groovy.util.i18n", Locale.FRENCH, cl)
            results << rb
            println "fr"
            println "'${rb.getString('yes')}'"
            println "'${rb.getString('upvote')}'"
            assert rb.getString('yes') == 'oui'
            assert rb.getString('upvote') == '+1'
        }
        assert results.size() == 4
    }
}

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy ResourceBundleTest.groovy source code file:

new blog posts

 

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.