KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > displaytag > util > HtmlTagUtilTest


1 package org.displaytag.util;
2
3 import junit.framework.TestCase;
4
5
6 /**
7  * Test case for org.displaytag.util.HtmlTagUtil.
8  * @author Fabrizio Giustina
9  * @version $Revision: 707 $ ($Author: fgiust $)
10  */

11 public class HtmlTagUtilTest extends TestCase
12 {
13
14     /**
15      * @see junit.framework.TestCase#getName()
16      */

17     public String JavaDoc getName()
18     {
19         return getClass().getName() + "." + super.getName();
20     }
21
22     /**
23      * Test for the stripHTMLTags() method.
24      */

25     public void testStripHtmlTagsSimple()
26     {
27         assertEquals("well done", HtmlTagUtil.stripHTMLTags("<strong>well</strong> done"));
28     }
29
30     /**
31      * Test for the stripHTMLTags() method.
32      */

33     public void testStripHtmlTagsNoHtml()
34     {
35         assertEquals("well done", HtmlTagUtil.stripHTMLTags("well done"));
36     }
37
38     /**
39      * Test for the stripHTMLTags() method.
40      */

41     public void testStripHtmlTagsWithQuote()
42     {
43         assertEquals("&quot;well&quot; done", HtmlTagUtil.stripHTMLTags("\"well\" done"));
44     }
45
46     /**
47      * Test for the stripHTMLTags() method.
48      */

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     /**
56      * Test for the stripHTMLTags() method.
57      */

58     public void testStripHtmlUnbalancedOpenStart()
59     {
60         assertEquals("", HtmlTagUtil.stripHTMLTags("<well done"));
61     }
62
63     /**
64      * Test for the stripHTMLTags() method.
65      */

66     public void testStripHtmlUnbalancedOpenMiddle()
67     {
68         assertEquals("well ", HtmlTagUtil.stripHTMLTags("well <done"));
69     }
70
71     /**
72      * Test for the stripHTMLTags() method.
73      */

74     public void testStripHtmlUnbalancedClosed()
75     {
76         assertEquals("well> done", HtmlTagUtil.stripHTMLTags("well> done"));
77     }
78
79     /**
80      * Test for the abbreviateHtmlString() method.
81      */

82     public void testAbbreviateHtmlStringByLengthNoHtml()
83     {
84         assertEquals("well...", HtmlTagUtil.abbreviateHtmlString("well done", 4, false));
85     }
86
87     /**
88      * Test for the abbreviateHtmlString() method.
89      */

90     public void testAbbreviateHtmlStringByLengthShorter()
91     {
92         assertEquals("well done", HtmlTagUtil.abbreviateHtmlString("well done", 9, false));
93     }
94
95     /**
96      * Test for the abbreviateHtmlString() method.
97      */

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     /**
107      * Test for the abbreviateHtmlString() method.
108      */

109     public void testAbbreviateHtmlStringByLengthEntity()
110     {
111         assertEquals("&amp; wel...", HtmlTagUtil.abbreviateHtmlString("&amp; well done", 5, false));
112     }
113
114     /**
115      * Test for the abbreviateHtmlString() method.
116      */

117     public void testAbbreviateHtmlStringByLengthBrokenEntity()
118     {
119         assertEquals("&amp;...", HtmlTagUtil.abbreviateHtmlString("&amp; well done", 1, false));
120     }
121
122     /**
123      * Test for the abbreviateHtmlString() method.
124      */

125     public void testAbbreviateHtmlStringByLengthUnescapedAmpersand()
126     {
127         assertEquals("& well d...", HtmlTagUtil.abbreviateHtmlString("& well done", 8, false));
128     }
129
130     /**
131      * Test for the abbreviateHtmlString() method.
132      */

133     public void testAbbreviateHtmlStringByLengthHtmlSimple()
134     {
135         assertEquals("<strong>well...</strong>", HtmlTagUtil.abbreviateHtmlString(
136             "<strong>well done</strong>",
137             4,
138             false));
139     }
140
141     /**
142      * Test for the abbreviateHtmlString() method.
143      */

144     public void testAbbreviateHtmlStringByLengthHtmlNoClosingTag()
145     {
146         assertEquals("well<br> ...", HtmlTagUtil.abbreviateHtmlString("well<br> done", 5, false));
147     }
148
149     /**
150      * Test for the abbreviateHtmlString() method.
151      */

152     public void testAbbreviateHtmlStringByLengthHtmlEndingTag()
153     {
154         assertEquals("well<br>", HtmlTagUtil.abbreviateHtmlString("well<br>", 5, false));
155     }
156
157     /**
158      * Test for the abbreviateHtmlString() method.
159      */

160     public void testAbbreviateHtmlStringByLengthHtmlEmptyTag()
161     {
162         assertEquals("well <br/> ...", HtmlTagUtil.abbreviateHtmlString("well <br/> done", 6, false));
163     }
164
165     /**
166      * Test for the abbreviateHtmlString() method.
167      */

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     /**
177      * Test for the abbreviateHtmlString() method.
178      */

179     public void testAbbreviateHtmlStringByNumberOfWordsNoHtml()
180     {
181         assertEquals("well...", HtmlTagUtil.abbreviateHtmlString("well done", 1, true));
182     }
183
184     /**
185      * Test for the abbreviateHtmlString() method.
186      */

187     public void testAbbreviateHtmlStringByNumberOfWordsShorter()
188     {
189         assertEquals("well done", HtmlTagUtil.abbreviateHtmlString("well done", 2, true));
190     }
191
192     /**
193      * Test for the abbreviateHtmlString() method.
194      */

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     /**
204      * Test for the abbreviateHtmlString() method.
205      */

206     public void testAbbreviateHtmlStringByLengthNumberOfWordsHtmlSimple()
207     {
208         assertEquals("<strong>well...</strong>", HtmlTagUtil
209             .abbreviateHtmlString("<strong>well done</strong>", 1, true));
210     }
211
212     /**
213      * Test for the abbreviateHtmlString() method.
214      */

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