TextUtilTestpublic class TextUtilTest extends TestCase Unit test for {@link TextUtil}. |
Fields Summary |
---|
private static char | EURO_SIGN |
Methods Summary |
---|
public void | testEscape()
assertEquals("", TextUtil.escapeHTML(""));
assertEquals(" ", TextUtil.escapeHTML(" "));
assertEquals("Hello World", TextUtil.escapeHTML("Hello World"));
assertEquals("Hello & World", TextUtil.escapeHTML("Hello & World"));
assertEquals("Cost is 1999€ and this is cheap", TextUtil.escapeHTML("Cost is 1999" + EURO_SIGN + " and this is cheap"));
assertEquals("Now some <> and < - > and we have </ and />", TextUtil.escapeHTML("Now some <> and < - > and we have </ and />"));
assertEquals("<?xml version="1.0" encoding="UTF-8"?>", TextUtil.escapeHTML("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
| public void | testEscapeEmpty()
assertEquals("", TextUtil.escapeHTML("", true));
assertEquals(" ", TextUtil.escapeHTML(" ", true));
assertEquals("Hello World", TextUtil.escapeHTML("Hello World", true));
assertEquals("Hello & World", TextUtil.escapeHTML("Hello & World", true));
assertEquals("Cost is 1999€ and this is cheap", TextUtil.escapeHTML("Cost is 1999" + EURO_SIGN + " and this is cheap", true));
assertEquals("Now some <> and < - > and we have </ and />", TextUtil.escapeHTML("Now some <> and < - > and we have </ and />", true));
assertEquals("<?xml version="1.0" encoding="UTF-8"?>", TextUtil.escapeHTML("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", true));
| public void | testLongText()
// TextUtil behaves special internally for long texts
String s = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" +
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" +
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 and now s" +
"ome < that should be escaped. But this text is to long (> 300)";
String res = TextUtil.escapeHTML(s);
assertEquals(368, res.length());
assertTrue(res.indexOf("<") == -1);
assertTrue(res.indexOf(">") == -1);
|
|