Code example for AttributedString

Methods: addAttribute

0
     * @tests java.text.AttributedString.addAttribute(AttributedCharacterIterator, 
     *        Object) 
     */ 
    public void test_addAttributeLjava_text_AttributedCharacterIterator$AttributeLjava_lang_Object() { 
        // regression for Harmony-1244 
        AttributedString as = new AttributedString("123", new WeakHashMap());
 
        as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, "english");
        as.addAttribute(AttributedCharacterIterator.Attribute.INPUT_METHOD_SEGMENT,
                                                                "input method"); 
        as.addAttribute(AttributedCharacterIterator.Attribute.READING, "reading");
 
        try { 
            as.addAttribute(null, new TreeSet());
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected 
        } 
        try { 
            as.addAttribute(null, null);
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected 
        } 
    }