Code example for NamespaceSupport

Methods: declarePrefix, getPrefix, pushContext

0
            // Expected. 
        } 
    } 
 
    public void testDeclare_GetPrefix() { 
        ns.pushContext();
 
        // Part 1: Check that xml and xmlns are not accepted as prefixes. 
        assertFalse("Test 1: Invalid prefix accepted.",
                ns.declarePrefix("xml", marketUri));
 
        assertFalse("Test 2: Invalid prefix accepted.",
                ns.declarePrefix("xmlns", marketUri));
 
        // Part 2: Check that declarePrefix and getPrefix work for valid 
        // prefixes. 
        assertTrue("Test 3: Valid prefix not accepted.",
                ns.declarePrefix("ak", marketUri));
 
        assertTrue("Test 4: Incorrect prefix returned.",
                ns.getPrefix(marketUri).equals("ak"));
 
        assertTrue("Test 5: Valid prefix not accepted.",
                ns.declarePrefix("bk", marketUri));
 
        assertTrue("Test 6: Incorrect prefix returned.",
                expected.contains(ns.getPrefix(marketUri)));
 
        assertTrue("Test 7: Valid prefix not accepted.",
                ns.declarePrefix("", defaultUri));
 
        // Part 3: Negative Tests for getPrefix. 
        assertNull("Test 8: Non-null value returned for the URI that is " +
                "assigned to the default namespace.", 
                ns.getPrefix(defaultUri));
 
        assertNull("Test 9: Non-null value returned for an unassigned URI.",
                ns.getPrefix(defaultUri + "/42"));
    } 
 
    @SuppressWarnings("unchecked") 
    public void testGetPrefixesLjava_lang_String() { 
        ArrayList<String> prefixes;