Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
115   243   11   10,45
0   141   0,1   11
11     1  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  CategoryTest       Line # 42 115 0% 11 0 100% 1.0
 
  (20)
 
1    /*
2    * Copyright (c) 2003-2006, Simon Brown
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *
8    * - Redistributions of source code must retain the above copyright
9    * notice, this list of conditions and the following disclaimer.
10    *
11    * - Redistributions in binary form must reproduce the above copyright
12    * notice, this list of conditions and the following disclaimer in
13    * the documentation and/or other materials provided with the
14    * distribution.
15    *
16    * - Neither the name of Pebble nor the names of its contributors may
17    * be used to endorse or promote products derived from this software
18    * without specific prior written permission.
19    *
20    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23    * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30    * POSSIBILITY OF SUCH DAMAGE.
31    */
32    package net.sourceforge.pebble.domain;
33   
34    import java.util.List;
35   
36   
37    /**
38    * Tests for the Category class.
39    *
40    * @author Simon Brown
41    */
 
42    public class CategoryTest extends SingleBlogTestCase {
43   
44    private Category category;
45   
 
46  20 toggle protected void setUp() throws Exception {
47  20 super.setUp();
48   
49  20 category = new Category("id", "name");
50    }
51   
52    /**
53    * Tests that toString() works.
54    */
 
55  2 toggle public void testToString() {
56  2 assertEquals("name", category.toString());
57    }
58   
59    /**
60    * Tests for the hasParent() method.
61    */
 
62  2 toggle public void testHasParent() {
63  2 Category java = new Category("/java", "Java");
64  2 Category junit = new Category("/java/junit", "JUnit");
65  2 java.addSubCategory(junit);
66  2 assertTrue(junit.hasParent(java));
67    }
68   
69    /**
70    * Tests for the getParent() method.
71    */
 
72  2 toggle public void testGetParent() {
73  2 Category java = new Category("/java", "Java");
74  2 Category junit = new Category("/java/junit", "JUnit");
75  2 java.addSubCategory(junit);
76  2 assertEquals(java, junit.getParent());
77    }
78   
79    /**
80    * Tests for the addSubCategories() method.
81    */
 
82  2 toggle public void testAddSubCategories() {
83  2 Category java = new Category("/java", "Java");
84  2 Category junit = new Category("/java/junit", "JUnit");
85  2 java.addSubCategory(junit);
86  2 assertEquals(1, java.getSubCategories().size());
87  2 assertEquals(junit, java.getSubCategories().get(0));
88   
89  2 Category jdbc = new Category("/java/jdbc", "JDBC");
90  2 java.addSubCategory(jdbc);
91  2 assertEquals(2, java.getSubCategories().size());
92  2 assertEquals(junit, java.getSubCategories().get(0));
93  2 assertEquals(jdbc, java.getSubCategories().get(1));
94   
95    // can't add the same category twice
96  2 java.addSubCategory(jdbc);
97  2 assertEquals(2, java.getSubCategories().size());
98  2 assertEquals(junit, java.getSubCategories().get(0));
99  2 assertEquals(jdbc, java.getSubCategories().get(1));
100    }
101   
102    /**
103    * Tests for the removeSubCategories() method.
104    */
 
105  2 toggle public void testRemoveSubCategories() {
106  2 Category java = new Category("/java", "Java");
107  2 Category junit = new Category("/java/junit", "JUnit");
108  2 Category jdbc = new Category("/java/jdbc", "JDBC");
109  2 java.addSubCategory(junit);
110  2 java.addSubCategory(jdbc);
111  2 assertEquals(2, java.getSubCategories().size());
112   
113  2 java.removeSubCategory(junit);
114  2 assertEquals(1, java.getSubCategories().size());
115  2 assertEquals(jdbc, java.getSubCategories().get(0));
116   
117  2 java.removeSubCategory(jdbc);
118  2 assertEquals(0, java.getSubCategories().size());
119   
120    // can't remove a category that hasn't been added
121  2 java.removeSubCategory(jdbc);
122  2 assertEquals(0, java.getSubCategories().size());
123    }
124   
125    /**
126    * Tests the getPermalink() method.
127    */
 
128  2 toggle public void testGetPermalink() {
129  2 Category root = new Category("/", "All");
130  2 root.setBlog(blog);
131  2 Category java = new Category("/java", "Java");
132  2 java.setBlog(blog);
133  2 Category junit = new Category("/java/junit", "JUnit");
134  2 junit.setBlog(blog);
135   
136  2 assertEquals("http://www.yourdomain.com/blog/categories/", root.getPermalink());
137  2 assertEquals("http://www.yourdomain.com/blog/categories/java/", java.getPermalink());
138  2 assertEquals("http://www.yourdomain.com/blog/categories/java/junit/", junit.getPermalink());
139    }
140   
141    /**
142    * Tests for the tags.
143    */
 
144  2 toggle public void testTagsSeparatedByCommas() {
145  2 Category root = new Category("/", "All");
146  2 root.setBlog(blog);
147  2 root.setTags("blog");
148  2 Category java = new Category("/java", "Java");
149  2 java.setBlog(blog);
150  2 java.setTags("java");
151  2 Category junit = new Category("/java/junit", "JUnit");
152  2 junit.setBlog(blog);
153  2 junit.setTags("junit, automatedunittesting");
154   
155  2 assertEquals("blog", root.getTags());
156  2 assertEquals(1, root.getTagsAsList().size());
157  2 assertEquals(blog.getTag("blog"), root.getTagsAsList().get(0));
158  2 assertEquals("java", java.getTags());
159  2 assertEquals(1, java.getTagsAsList().size());
160  2 assertEquals(blog.getTag("java"), java.getTagsAsList().get(0));
161  2 assertEquals("junit automatedunittesting", junit.getTags());
162  2 assertEquals(2, junit.getTagsAsList().size());
163  2 assertEquals(blog.getTag("junit"), junit.getTagsAsList().get(0));
164  2 assertEquals(blog.getTag("automatedunittesting"), junit.getTagsAsList().get(1));
165   
166  2 List tags = root.getTagsAsList();
167  2 assertEquals(tags, root.getAllTags());
168   
169  2 tags = java.getTagsAsList();
170  2 tags.addAll(root.getTagsAsList());
171  2 assertEquals(tags, java.getAllTags());
172   
173  2 tags = junit.getTagsAsList();
174  2 tags.addAll(java.getTagsAsList());
175  2 tags.addAll(root.getTagsAsList());
176  2 assertEquals(tags, junit.getAllTags());
177    }
178   
179    /**
180    * Tests for the tags.
181    */
 
182  2 toggle public void testTagsSeparatedByWhitespace() {
183  2 Category root = new Category("/", "All");
184  2 root.setBlog(blog);
185  2 root.setTags("blog");
186  2 Category java = new Category("/java", "Java");
187  2 java.setBlog(blog);
188  2 java.setTags("java");
189  2 Category junit = new Category("/java/junit", "JUnit");
190  2 junit.setBlog(blog);
191  2 junit.setTags("junit automatedunittesting");
192   
193  2 assertEquals("blog", root.getTags());
194  2 assertEquals(1, root.getTagsAsList().size());
195  2 assertEquals(blog.getTag("blog"), root.getTagsAsList().get(0));
196  2 assertEquals("java", java.getTags());
197  2 assertEquals(1, java.getTagsAsList().size());
198  2 assertEquals(blog.getTag("java"), java.getTagsAsList().get(0));
199  2 assertEquals("junit automatedunittesting", junit.getTags());
200  2 assertEquals(2, junit.getTagsAsList().size());
201  2 assertEquals(blog.getTag("junit"), junit.getTagsAsList().get(0));
202  2 assertEquals(blog.getTag("automatedunittesting"), junit.getTagsAsList().get(1));
203   
204  2 List tags = root.getTagsAsList();
205  2 assertEquals(tags, root.getAllTags());
206   
207  2 tags = java.getTagsAsList();
208  2 tags.addAll(root.getTagsAsList());
209  2 assertEquals(tags, java.getAllTags());
210   
211  2 tags = junit.getTagsAsList();
212  2 tags.addAll(java.getTagsAsList());
213  2 tags.addAll(root.getTagsAsList());
214  2 assertEquals(tags, junit.getAllTags());
215    }
216   
217    /**
218    * Tests for the isRootCategory() method.
219    */
 
220  2 toggle public void testIsRootCategory() {
221  2 Category root = new Category("/", "All");
222  2 Category java = new Category("/java", "Java");
223   
224  2 assertTrue(root.isRootCategory());
225  2 assertFalse(java.isRootCategory());
226    }
227   
228    /**
229    * Tests for the getNumberOfParents() method.
230    */
 
231  2 toggle public void testGetNumberOfParents() {
232  2 Category root = new Category("/", "All");
233  2 Category java = new Category("/java", "Java");
234  2 Category junit = new Category("/java/junit", "JUnit");
235  2 root.addSubCategory(java);
236  2 java.addSubCategory(junit);
237   
238  2 assertEquals(0, root.getNumberOfParents());
239  2 assertEquals(1, java.getNumberOfParents());
240  2 assertEquals(2, junit.getNumberOfParents());
241    }
242   
243    }