Code example for ResourceBundle

Methods: containsKey, getString, keySet

0
    public void test_getBundle_LStringLControl() { 
        Locale.setDefault(LOCALE_FRFR);
        ResourceBundle.clearCache();
        bundle = ResourceBundle.getBundle(SUBFOLDER_PROPERTIES_NAME,
                DEFAULT_CONTROL);
        assertEquals(6, bundle.keySet().size());
        assertEquals("frFRChildValue2", bundle.getString("subChild2"));
        assertEquals("subParentValue1", bundle.getString("subParent1"));
        assertEquals("frFRValue4", bundle.getString("subParent4"));
        assertFalse(bundle.containsKey("property"));
 
        ResourceBundle.clearCache();
        try { 
            ResourceBundle.getBundle("wrongName", DEFAULT_CONTROL);
            fail("Should throw MissingResourceException");
        } catch (MissingResourceException e) {
            // expected 
        } 
        try { 
            ResourceBundle.getBundle(null, DEFAULT_CONTROL);
            fail("Should throw NullPointerException");