Code example for AttributedString

Methods: addAttributes

0
     *        to add attributes to AttributesString. Case 2: Try to add 
     *        null-attributes to AttributesString. Case 3: Try to add attributes 
     *        to AttributesString using incorrect index. 
     */ 
    public void test_addAttributesLjava_util_MapII() { 
        AttributedString as = new AttributedString("test");
        Map<AttributedCharacterIterator.Attribute, String> whm = new WeakHashMap<AttributedCharacterIterator.Attribute, String>();
 
        // case 1: Try to add attributes to AttributesString. 
        try { 
            whm.put(new TestAttributedCharacterIteratorAttribute("test1"),
                    "value1"); 
            whm.put(new TestAttributedCharacterIteratorAttribute("test2"),
                    "value2"); 
            whm.put(new TestAttributedCharacterIteratorAttribute("test3"),
                    "value3"); 
            as.addAttributes(whm, 0, 3);
        } catch (Exception e) {
            fail("Unexpected exception " + e.toString());
        } 
 
        // case 2: Try to add null-attributes to AttributesString. 
        try { 
            as.addAttributes(null, 0, 3);
            fail("Expected NullPointerException was not thrown");
        } catch (NullPointerException e) {
            // expected 
        } 
 
        // case 3: Try to add attributes to AttributesString using incorrect 
        // index. 
        try { 
            as.addAttributes(whm, 0, 0);
            fail("Expected IllegalArgumentException was not thrown");
        } catch (IllegalArgumentException e) {
            // expected 
        } 
    }