KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.displaytag.util;
2
3 import java.util.ArrayList JavaDoc;
4
5 import junit.framework.TestCase;
6
7 import org.apache.commons.lang.ClassUtils;
8 import org.displaytag.model.Cell;
9 import org.displaytag.model.Column;
10 import org.displaytag.model.HeaderCell;
11 import org.displaytag.model.Row;
12 import org.displaytag.model.TableModel;
13 import org.displaytag.pagination.NumberedPage;
14 import org.displaytag.pagination.Pagination;
15 import org.displaytag.pagination.SmartListHelper;
16 import org.displaytag.properties.TableProperties;
17 import org.displaytag.tags.ColumnTag;
18
19
20 /**
21  * Check that toString() methods are constructed appropriately, uses the correct style and that there aren't stupid NPE
22  * bugs in them.
23  * @author Fabrizio Giustina
24  * @version $Revision: 914 $ ($Author: fgiust $)
25  */

26 public class ToStringTest extends TestCase
27 {
28
29     /**
30      * @see junit.framework.TestCase#getName()
31      */

32     public String JavaDoc getName()
33     {
34         return getClass().getName() + "." + super.getName();
35     }
36
37     /**
38      * ToString methods should be costructed using toStringBuilder and the <code>ShortToStringStyle.SHORT_STYLE</code>
39      * style.
40      * @param object test instance
41      */

42     private void checkToString(Object JavaDoc object)
43     {
44         String JavaDoc toString = object.toString();
45         assertTrue(toString.startsWith(ClassUtils.getShortClassName(object, null)));
46     }
47
48     /**
49      * ToString() test.
50      */

51     public void testSmartListHelper()
52     {
53         checkToString(new SmartListHelper(new ArrayList JavaDoc(), 100, 10, TableProperties.getInstance(null), false));
54     }
55
56     /**
57      * ToString() test.
58      */

59     public void testNumberedPage()
60     {
61         checkToString(new NumberedPage(1, false));
62     }
63
64     /**
65      * ToString() test.
66      */

67     public void testPagination()
68     {
69         checkToString(new Pagination(null, null));
70     }
71
72     /**
73      * ToString() test.
74      */

75     public void testCell()
76     {
77         checkToString(new Cell(null));
78     }
79
80     /**
81      * ToString() test.
82      */

83     public void testHeaderCell()
84     {
85         checkToString(new HeaderCell());
86     }
87
88     /**
89      * ToString() test.
90      */

91     public void testColumn()
92     {
93         checkToString(new Column(new HeaderCell(), null, null));
94     }
95
96     /**
97      * ToString() test.
98      */

99     public void testRow()
100     {
101         checkToString(new Row(null, 0));
102     }
103
104     /**
105      * ToString() test.
106      */

107     public void testTableModel()
108     {
109         checkToString(new TableModel(null, null, null));
110     }
111
112     /**
113      * ToString() test.
114      */

115     public void testColumnTag()
116     {
117         checkToString(new ColumnTag());
118     }
119
120 }
121
Popular Tags