Search in sources :

Example 96 with MissingResourceException

use of java.util.MissingResourceException in project robovm by robovm.

the class MissingResourceExceptionTest method test_ConstructorLjava_lang_StringLjava_lang_StringLjava_lang_String.

/**
     * java.util.MissingResourceException#MissingResourceException(java.lang.String,
     *        java.lang.String, java.lang.String)
     */
public void test_ConstructorLjava_lang_StringLjava_lang_StringLjava_lang_String() {
    // Test for method java.util.MissingResourceException(java.lang.String,
    // java.lang.String, java.lang.String)
    assertNotNull(new MissingResourceException("Detail string", "Class name string", "Key string"));
    assertNotNull(new MissingResourceException(null, "Class name string", "Key string"));
    assertNotNull(new MissingResourceException("Detail string", null, "Key string"));
    assertNotNull(new MissingResourceException("Detail string", "Class name string", null));
    try {
        ResourceBundle.getBundle("Non-ExistentBundle");
    } catch (MissingResourceException e) {
        return;
    }
    fail("Failed to generate expected exception");
}
Also used : MissingResourceException(java.util.MissingResourceException)

Example 97 with MissingResourceException

use of java.util.MissingResourceException in project robovm by robovm.

the class Main method testIso3.

/*
     * Test that we can set and get an ISO3 language code.  Support for this
     * is expected by the Android framework.
     */
static void testIso3() {
    Locale loc;
    loc = new Locale("en", "US");
    System.out.println("loc: " + loc);
    System.out.println(" iso3=" + loc.getISO3Language());
    loc = new Locale("eng", "USA");
    System.out.println("loc: " + loc);
    try {
        System.out.println(" iso3=" + loc.getISO3Language());
    } catch (MissingResourceException mre) {
        System.err.println("couldn't get iso3 language");
    }
}
Also used : Locale(java.util.Locale) MissingResourceException(java.util.MissingResourceException)

Example 98 with MissingResourceException

use of java.util.MissingResourceException in project robovm by robovm.

the class ResourceBundleTest method test_getBundleLjava_lang_StringLjava_util_Locale.

/**
     * java.util.ResourceBundle#getBundle(java.lang.String,
     *        java.util.Locale)
     */
public void test_getBundleLjava_lang_StringLjava_util_Locale() {
    ResourceBundle bundle;
    String name = "tests.support.Support_TestResource";
    Locale defLocale = Locale.getDefault();
    Locale.setDefault(new Locale("en", "US"));
    bundle = ResourceBundle.getBundle(name, new Locale("fr", "FR", "VAR"));
    assertEquals("Wrong bundle fr_FR_VAR", "frFRVARValue4", bundle.getString("parent4"));
    bundle = ResourceBundle.getBundle(name, new Locale("fr", "FR", "v1"));
    assertEquals("Wrong bundle fr_FR_v1", "frFRValue4", bundle.getString("parent4"));
    bundle = ResourceBundle.getBundle(name, new Locale("fr", "US", "VAR"));
    assertEquals("Wrong bundle fr_US_var", "frValue4", bundle.getString("parent4"));
    bundle = ResourceBundle.getBundle(name, new Locale("de", "FR", "VAR"));
    assertEquals("Wrong bundle de_FR_var", "enUSValue4", bundle.getString("parent4"));
    Locale.setDefault(new Locale("fr", "FR", "VAR"));
    bundle = ResourceBundle.getBundle(name, new Locale("de", "FR", "v1"));
    assertEquals("Wrong bundle de_FR_var 2", "frFRVARValue4", bundle.getString("parent4"));
    Locale.setDefault(new Locale("de", "US"));
    bundle = ResourceBundle.getBundle(name, new Locale("de", "FR", "var"));
    assertEquals("Wrong bundle de_FR_var 2", "parentValue4", bundle.getString("parent4"));
    try {
        ResourceBundle.getBundle(null, Locale.US);
        fail("NullPointerException expected");
    } catch (NullPointerException ee) {
    //expected
    }
    try {
        ResourceBundle.getBundle("blah", (Locale) null);
        fail("NullPointerException expected");
    } catch (NullPointerException ee) {
    //expected
    }
    try {
        ResourceBundle.getBundle("", new Locale("xx", "yy"));
        fail("MissingResourceException expected");
    } catch (MissingResourceException ee) {
    //expected
    }
}
Also used : Locale(java.util.Locale) MissingResourceException(java.util.MissingResourceException) ResourceBundle(java.util.ResourceBundle)

Example 99 with MissingResourceException

use of java.util.MissingResourceException 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)

Example 100 with MissingResourceException

use of java.util.MissingResourceException in project robovm by robovm.

the class ResourceBundleTest method test_getBundleLjava_lang_String.

public void test_getBundleLjava_lang_String() {
    ResourceBundle bundle;
    String name = "tests.support.Support_TestResource";
    Locale defLocale = Locale.getDefault();
    Locale.setDefault(new Locale("en", "US"));
    bundle = ResourceBundle.getBundle(name);
    assertEquals("enUSValue4", bundle.getString("parent4"));
    Locale.setDefault(new Locale("fr", "FR", "v1"));
    bundle = ResourceBundle.getBundle(name);
    assertEquals("Wrong bundle fr_FR_v1", "frFRValue4", bundle.getString("parent4"));
    Locale.setDefault(new Locale("fr", "US", "VAR"));
    bundle = ResourceBundle.getBundle(name);
    assertEquals("Wrong bundle fr_US_var", "frValue4", bundle.getString("parent4"));
    Locale.setDefault(new Locale("de", "FR", "VAR"));
    bundle = ResourceBundle.getBundle(name);
    assertEquals("Wrong bundle de_FR_var", "parentValue4", bundle.getString("parent4"));
    Locale.setDefault(new Locale("de", "FR", "v1"));
    bundle = ResourceBundle.getBundle(name);
    assertEquals("Wrong bundle de_FR_var 2", "parentValue4", bundle.getString("parent4"));
    Locale.setDefault(new Locale("de", "FR", "var"));
    bundle = ResourceBundle.getBundle(name);
    assertEquals("Wrong bundle de_FR_var 2", "parentValue4", bundle.getString("parent4"));
    try {
        ResourceBundle.getBundle(null);
        fail("NullPointerException expected");
    } catch (NullPointerException ee) {
    //expected
    }
    try {
        ResourceBundle.getBundle("");
        fail("MissingResourceException expected");
    } catch (MissingResourceException ee) {
    //expected
    }
    Locale.setDefault(defLocale);
}
Also used : Locale(java.util.Locale) MissingResourceException(java.util.MissingResourceException) ResourceBundle(java.util.ResourceBundle)

Aggregations

MissingResourceException (java.util.MissingResourceException)151 ResourceBundle (java.util.ResourceBundle)77 Locale (java.util.Locale)66 ArrayList (java.util.ArrayList)10 IOException (java.io.IOException)8 MessageFormat (java.text.MessageFormat)8 File (java.io.File)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 SMSException (com.sun.identity.sm.SMSException)6 PropertyResourceBundle (java.util.PropertyResourceBundle)6 Secure.getString (android.provider.Settings.Secure.getString)5 SSOException (com.iplanet.sso.SSOException)5 InputStream (java.io.InputStream)4 ISResourceBundle (com.sun.identity.common.ISResourceBundle)3 Enumeration (java.util.Enumeration)3 Iterator (java.util.Iterator)3 List (java.util.List)3 Set (java.util.Set)3 AttributeSchema (com.sun.identity.sm.AttributeSchema)2