1 package org.displaytag.util; 2 3 import junit.framework.TestCase; 4 5 6 11 public class HtmlTagUtilTest extends TestCase 12 { 13 14 17 public String getName() 18 { 19 return getClass().getName() + "." + super.getName(); 20 } 21 22 25 public void testStripHtmlTagsSimple() 26 { 27 assertEquals("well done", HtmlTagUtil.stripHTMLTags("<strong>well</strong> done")); 28 } 29 30 33 public void testStripHtmlTagsNoHtml() 34 { 35 assertEquals("well done", HtmlTagUtil.stripHTMLTags("well done")); 36 } 37 38 41 public void testStripHtmlTagsWithQuote() 42 { 43 assertEquals(""well" done", HtmlTagUtil.stripHTMLTags("\"well\" done")); 44 } 45 46 49 public void testStripHtmlTagsMultiple() 50 { 51 assertEquals("well done again", HtmlTagUtil 52 .stripHTMLTags("<a HREF=\"go\"><strong>well <em>done</em></strong> again</a>")); 53 } 54 55 58 public void testStripHtmlUnbalancedOpenStart() 59 { 60 assertEquals("", HtmlTagUtil.stripHTMLTags("<well done")); 61 } 62 63 66 public void testStripHtmlUnbalancedOpenMiddle() 67 { 68 assertEquals("well ", HtmlTagUtil.stripHTMLTags("well <done")); 69 } 70 71 74 public void testStripHtmlUnbalancedClosed() 75 { 76 assertEquals("well> done", HtmlTagUtil.stripHTMLTags("well> done")); 77 } 78 79 82 public void testAbbreviateHtmlStringByLengthNoHtml() 83 { 84 assertEquals("well...", HtmlTagUtil.abbreviateHtmlString("well done", 4, false)); 85 } 86 87 90 public void testAbbreviateHtmlStringByLengthShorter() 91 { 92 assertEquals("well done", HtmlTagUtil.abbreviateHtmlString("well done", 9, false)); 93 } 94 95 98 public void testAbbreviateHtmlStringByLengthHtmlShorter() 99 { 100 assertEquals("<strong>well</strong> done", HtmlTagUtil.abbreviateHtmlString( 101 "<strong>well</strong> done", 102 10, 103 false)); 104 } 105 106 109 public void testAbbreviateHtmlStringByLengthEntity() 110 { 111 assertEquals("& wel...", HtmlTagUtil.abbreviateHtmlString("& well done", 5, false)); 112 } 113 114 117 public void testAbbreviateHtmlStringByLengthBrokenEntity() 118 { 119 assertEquals("&...", HtmlTagUtil.abbreviateHtmlString("& well done", 1, false)); 120 } 121 122 125 public void testAbbreviateHtmlStringByLengthUnescapedAmpersand() 126 { 127 assertEquals("& well d...", HtmlTagUtil.abbreviateHtmlString("& well done", 8, false)); 128 } 129 130 133 public void testAbbreviateHtmlStringByLengthHtmlSimple() 134 { 135 assertEquals("<strong>well...</strong>", HtmlTagUtil.abbreviateHtmlString( 136 "<strong>well done</strong>", 137 4, 138 false)); 139 } 140 141 144 public void testAbbreviateHtmlStringByLengthHtmlNoClosingTag() 145 { 146 assertEquals("well<br> ...", HtmlTagUtil.abbreviateHtmlString("well<br> done", 5, false)); 147 } 148 149 152 public void testAbbreviateHtmlStringByLengthHtmlEndingTag() 153 { 154 assertEquals("well<br>", HtmlTagUtil.abbreviateHtmlString("well<br>", 5, false)); 155 } 156 157 160 public void testAbbreviateHtmlStringByLengthHtmlEmptyTag() 161 { 162 assertEquals("well <br/> ...", HtmlTagUtil.abbreviateHtmlString("well <br/> done", 6, false)); 163 } 164 165 168 public void testAbbreviateHtmlStringByLengthHtmlComplex() 169 { 170 assertEquals("<a HREF=\"link\">well...</a>", HtmlTagUtil.abbreviateHtmlString( 171 "<a HREF=\"link\">well <strong>done</strong></a>", 172 4, 173 false)); 174 } 175 176 179 public void testAbbreviateHtmlStringByNumberOfWordsNoHtml() 180 { 181 assertEquals("well...", HtmlTagUtil.abbreviateHtmlString("well done", 1, true)); 182 } 183 184 187 public void testAbbreviateHtmlStringByNumberOfWordsShorter() 188 { 189 assertEquals("well done", HtmlTagUtil.abbreviateHtmlString("well done", 2, true)); 190 } 191 192 195 public void testAbbreviateHtmlStringByNumberOfWordsHtmlShorter() 196 { 197 assertEquals("<strong>well</strong> done", HtmlTagUtil.abbreviateHtmlString( 198 "<strong>well</strong> done", 199 3, 200 true)); 201 } 202 203 206 public void testAbbreviateHtmlStringByLengthNumberOfWordsHtmlSimple() 207 { 208 assertEquals("<strong>well...</strong>", HtmlTagUtil 209 .abbreviateHtmlString("<strong>well done</strong>", 1, true)); 210 } 211 212 215 public void testAbbreviateHtmlStringByNumberOfWordsHtmlComplex() 216 { 217 assertEquals("<a HREF=\"link\">well...</a>", HtmlTagUtil.abbreviateHtmlString( 218 "<a HREF=\"link\">well <strong>done</strong></a>", 219 1, 220 true)); 221 } 222 223 } | Popular Tags |