Search in sources :

Example 1 with B

use of tests.api.java.util.support.B in project robovm by robovm.

the class ResourceBundleTest method test_getBundleLjava_lang_StringLjava_util_LocaleLjava_lang_ClassLoader.

/**
     * java.util.ResourceBundle#getBundle(java.lang.String,
     *        java.util.Locale, java.lang.ClassLoader)
     */
@KnownFailure("It's not allowed to pass null as parent class loader to" + " a new ClassLoader anymore. Maybe we need to change" + " URLClassLoader to allow this? It's not specified.")
public void test_getBundleLjava_lang_StringLjava_util_LocaleLjava_lang_ClassLoader() {
    String classPath = System.getProperty("java.class.path");
    StringTokenizer tok = new StringTokenizer(classPath, File.pathSeparator);
    Vector<URL> urlVec = new Vector<URL>();
    String resPackage = Support_Resources.RESOURCE_PACKAGE;
    try {
        while (tok.hasMoreTokens()) {
            String path = tok.nextToken();
            String url;
            if (new File(path).isDirectory())
                url = "file:" + path + resPackage + "subfolder/";
            else
                url = "jar:file:" + path + "!" + resPackage + "subfolder/";
            urlVec.addElement(new URL(url));
        }
    } catch (MalformedURLException e) {
    }
    URL[] urls = new URL[urlVec.size()];
    for (int i = 0; i < urlVec.size(); i++) urls[i] = urlVec.elementAt(i);
    URLClassLoader loader = new URLClassLoader(urls, null);
    String name = Support_Resources.RESOURCE_PACKAGE_NAME + ".hyts_resource";
    ResourceBundle bundle = ResourceBundle.getBundle(name, Locale.getDefault());
    assertEquals("Wrong value read", "parent", bundle.getString("property"));
    bundle = ResourceBundle.getBundle(name, Locale.getDefault(), loader);
    assertEquals("Wrong cached value", "resource", bundle.getString("property"));
    try {
        ResourceBundle.getBundle(null, Locale.getDefault(), loader);
        fail("NullPointerException expected");
    } catch (NullPointerException ee) {
    //expected
    }
    try {
        ResourceBundle.getBundle(name, null, loader);
        fail("NullPointerException expected");
    } catch (NullPointerException ee) {
    //expected
    }
    try {
        ResourceBundle.getBundle(name, Locale.getDefault(), (ClassLoader) null);
        fail("NullPointerException expected");
    } catch (NullPointerException ee) {
    //expected
    }
    try {
        ResourceBundle.getBundle("", Locale.getDefault(), loader);
        fail("MissingResourceException expected");
    } catch (MissingResourceException ee) {
    //expected
    }
    // Regression test for Harmony-3823
    B bb = new B();
    String s = bb.find("nonexistent");
    s = bb.find("name");
    assertEquals("Wrong property got", "Name", s);
}
Also used : MalformedURLException(java.net.MalformedURLException) B(tests.api.java.util.support.B) MissingResourceException(java.util.MissingResourceException) URL(java.net.URL) StringTokenizer(java.util.StringTokenizer) URLClassLoader(java.net.URLClassLoader) ResourceBundle(java.util.ResourceBundle) Vector(java.util.Vector) File(java.io.File) KnownFailure(dalvik.annotation.KnownFailure)

Aggregations

KnownFailure (dalvik.annotation.KnownFailure)1 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 MissingResourceException (java.util.MissingResourceException)1 ResourceBundle (java.util.ResourceBundle)1 StringTokenizer (java.util.StringTokenizer)1 Vector (java.util.Vector)1 B (tests.api.java.util.support.B)1