use of java.text.AttributedString in project robovm by robovm.
the class OldAttributedStringTest method test_addAttributeLjava_text_AttributedCharacterIterator$AttributeLjava_lang_ObjectII.
public void test_addAttributeLjava_text_AttributedCharacterIterator$AttributeLjava_lang_ObjectII() {
AttributedString as = new AttributedString("test");
as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, "a", 2, 3);
AttributedCharacterIterator it = as.getIterator();
assertEquals("non-null value limit", 2, it.getRunLimit(AttributedCharacterIterator.Attribute.LANGUAGE));
as = new AttributedString("test");
as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, null, 2, 3);
it = as.getIterator();
assertEquals("null value limit", 4, it.getRunLimit(AttributedCharacterIterator.Attribute.LANGUAGE));
try {
as = new AttributedString("test");
as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, null, -1, 3);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
// Expected
}
// regression for Harmony-1244
as = new AttributedString("123", new WeakHashMap());
try {
as.addAttribute(null, new TreeSet(), 0, 1);
fail("should throw NullPointerException");
} catch (NullPointerException e) {
// expected
}
try {
as.addAttribute(null, new TreeSet(), -1, 1);
fail("should throw NullPointerException");
} catch (NullPointerException e) {
// expected
}
}
use of java.text.AttributedString in project robovm by robovm.
the class OldAttributedStringTest method test_getIterator$Ljava_text_AttributedCharacterIterator$AttributeII.
/**
* java.text.AttributedString#getIterator(AttributedCharacterIterator.Attribute[],
* int, int) Test of method
* java.text.AttributedString#getIterator(AttributedCharacterIterator.Attribute[],
* int, int).
*/
public void test_getIterator$Ljava_text_AttributedCharacterIterator$AttributeII() {
String test = "Test string";
try {
Map<AttributedCharacterIterator.Attribute, String> hm = new HashMap<AttributedCharacterIterator.Attribute, String>();
AttributedCharacterIterator.Attribute[] aci = new AttributedCharacterIterator.Attribute[3];
aci[0] = new TestAttributedCharacterIteratorAttribute("att1");
aci[1] = new TestAttributedCharacterIteratorAttribute("att2");
aci[2] = new TestAttributedCharacterIteratorAttribute("att3");
hm.put(aci[0], "value1");
hm.put(aci[1], "value2");
AttributedString attrString = new AttributedString(test);
attrString.addAttributes(hm, 2, 4);
AttributedCharacterIterator it = attrString.getIterator(aci, 1, 5);
assertTrue("Incorrect iteration on AttributedString", it.getAttribute(aci[0]) == null);
assertTrue("Incorrect iteration on AttributedString", it.getAttribute(aci[1]) == null);
assertTrue("Incorrect iteration on AttributedString", it.getAttribute(aci[2]) == null);
it.next();
assertTrue("Incorrect iteration on AttributedString", it.getAttribute(aci[0]).equals("value1"));
assertTrue("Incorrect iteration on AttributedString", it.getAttribute(aci[1]).equals("value2"));
assertTrue("Incorrect iteration on AttributedString", it.getAttribute(aci[2]) == null);
try {
attrString.getIterator(aci, -1, 5);
fail("IllegalArgumentException is not thrown.");
} catch (IllegalArgumentException iae) {
//expected
}
try {
attrString.getIterator(aci, 6, 5);
fail("IllegalArgumentException is not thrown.");
} catch (IllegalArgumentException iae) {
//expected
}
try {
attrString.getIterator(aci, 3, 2);
fail("IllegalArgumentException is not thrown.");
} catch (IllegalArgumentException iae) {
//expected
}
} catch (Exception e) {
fail("Unexpected exceptiption " + e.toString());
}
}
use of java.text.AttributedString in project robovm by robovm.
the class OldAttributedStringTest method test_addAttributeLjava_text_AttributedCharacterIterator$AttributeLjava_lang_Object.
/**
* 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
}
}
use of java.text.AttributedString in project robovm by robovm.
the class OldAttributedStringTest method test_getIterator$Ljava_text_AttributedCharacterIterator$Attribute.
/**
* java.text.AttributedString#getIterator(AttributedCharacterIterator.Attribute[])
* Test of method
* java.text.AttributedString#getIterator(AttributedCharacterIterator.Attribute[]).
*/
public void test_getIterator$Ljava_text_AttributedCharacterIterator$Attribute() {
String test = "Test string";
try {
Map<AttributedCharacterIterator.Attribute, String> hm = new HashMap<AttributedCharacterIterator.Attribute, String>();
AttributedCharacterIterator.Attribute[] aci = new AttributedCharacterIterator.Attribute[3];
aci[0] = new TestAttributedCharacterIteratorAttribute("att1");
aci[1] = new TestAttributedCharacterIteratorAttribute("att2");
aci[2] = new TestAttributedCharacterIteratorAttribute("att3");
hm.put(aci[0], "value1");
hm.put(aci[1], "value2");
AttributedString attrString = new AttributedString(test, hm);
AttributedCharacterIterator it = attrString.getIterator(aci);
assertTrue("Incorrect iteration on AttributedString", it.getAttribute(aci[0]).equals("value1"));
assertTrue("Incorrect iteration on AttributedString", it.getAttribute(aci[1]).equals("value2"));
assertTrue("Incorrect iteration on AttributedString", it.getAttribute(aci[2]) == null);
} catch (Exception e) {
fail("Unexpected exceptiption " + e.toString());
}
}
use of java.text.AttributedString in project robovm by robovm.
the class OldAttributedStringTest method test_addAttributesLjava_util_MapII.
/**
* java.text.AttributedString#addAttributes(Map<? extends
* AttributedCharacterIterator.Attribute,?>, int, int) Tests of
* method java.text.AttributedString#addAttributes(Map<? extends
* AttributedCharacterIterator.Attribute,?>, int, int). Case 1: Try
* 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
}
// index.
try {
as.addAttributes(whm, 0, 0);
fail("Expected IllegalArgumentException was not thrown");
} catch (IllegalArgumentException e) {
// expected
}
}
Aggregations