Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
117   229   10   11,7
0   140   0,09   10
10     1  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  CategoryBuilderTest       Line # 42 117 0% 10 0 100% 1.0
 
  (18)
 
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   
35   
36   
37    /**
38    * Tests for the CategoryBuilder class.
39    *
40    * @author Simon Brown
41    */
 
42    public class CategoryBuilderTest extends SingleBlogTestCase {
43   
44    private CategoryBuilder builder;
45   
 
46  18 toggle protected void setUp() throws Exception {
47  18 super.setUp();
48  18 builder = new CategoryBuilder(blog);
49    }
50   
51    /**
52    * Tests that a root category is created by default.
53    */
 
54  2 toggle public void testRootCategoryCreatedByDefault() {
55  2 Category category = builder.getRootCategory();
56  2 assertNotNull(category);
57  2 assertTrue(category.isRootCategory());
58    }
59   
60    /**
61    * Tests that a root category can be added.
62    */
 
63  2 toggle public void testRootCategoryCanBeAdded() {
64  2 Category root = new Category("/", "/");
65  2 builder.addCategory(root);
66  2 root.setTags("blog");
67  2 Category category = builder.getRootCategory();
68  2 assertNotNull(category);
69  2 assertTrue(category.isRootCategory());
70  2 assertNull(category.getParent());
71  2 assertEquals("blog", category.getTags());
72    }
73   
74    /**
75    * Tests that a level 2 category can be added with parent.
76    */
 
77  2 toggle public void testLevel2CategoryCanBeAddedWithParent() {
78  2 Category root = new Category("/", "/");
79  2 Category java = new Category("/java", "Java");
80  2 builder.addCategory(root);
81  2 builder.addCategory(java);
82  2 root.setTags("blog");
83  2 java.setTags("java");
84   
85  2 Category category = (Category)builder.getRootCategory().getSubCategories().get(0);
86  2 assertNotNull(category);
87  2 assertEquals("/java", category.getId());
88  2 assertEquals("Java", category.getName());
89  2 assertEquals("java", category.getTags());
90  2 assertEquals(builder.getRootCategory(), category.getParent());
91    }
92   
93    /**
94    * Tests that a level 2 category can be added without parent.
95    */
 
96  2 toggle public void testLevel2CategoryCanBeAddedWithoutParent() {
97  2 Category java = new Category("/java", "Java");
98  2 builder.addCategory(java);
99  2 java.setTags("java");
100   
101  2 Category category = (Category)builder.getRootCategory().getSubCategories().get(0);
102  2 assertNotNull(category);
103  2 assertEquals("/java", category.getId());
104  2 assertEquals("Java", category.getName());
105  2 assertEquals("java", category.getTags());
106  2 assertEquals(builder.getRootCategory(), category.getParent());
107    }
108   
109    /**
110    * Tests that multiple level 2 categories can be added with parent.
111    */
 
112  2 toggle public void testLevel2CategoriesCanBeAddedWithParent() {
113  2 Category root = new Category("/", "/");
114  2 Category java = new Category("/java", "Java");
115  2 Category apple = new Category("/apple", "Apple");
116  2 builder.addCategory(root);
117  2 builder.addCategory(java);
118  2 builder.addCategory(apple);
119  2 root.setTags("blog");
120  2 java.setTags("java");
121  2 apple.setTags("apple");
122   
123  2 assertEquals(2, builder.getRootCategory().getSubCategories().size());
124  2 Category category = (Category)builder.getRootCategory().getSubCategories().get(0);
125  2 assertNotNull(category);
126  2 assertEquals("/java", category.getId());
127  2 assertEquals("Java", category.getName());
128  2 assertEquals("java", category.getTags());
129  2 category = (Category)builder.getRootCategory().getSubCategories().get(1);
130  2 assertNotNull(category);
131  2 assertEquals("/apple", category.getId());
132  2 assertEquals("Apple", category.getName());
133  2 assertEquals("apple", category.getTags());
134    }
135   
136    /**
137    * Tests that a multiple level 2 categories can be added without parent.
138    */
 
139  2 toggle public void testLevel2CategoriesCanBeAddedWithoutParent() {
140  2 Category java = new Category("/java", "Java");
141  2 Category apple = new Category("/apple", "Apple");
142  2 builder.addCategory(java);
143  2 builder.addCategory(apple);
144  2 java.setTags("java");
145  2 apple.setTags("apple");
146   
147  2 assertEquals(2, builder.getRootCategory().getSubCategories().size());
148  2 Category category = (Category)builder.getRootCategory().getSubCategories().get(0);
149  2 assertNotNull(category);
150  2 assertEquals("/java", category.getId());
151  2 assertEquals("Java", category.getName());
152  2 assertEquals("java", category.getTags());
153  2 category = (Category)builder.getRootCategory().getSubCategories().get(1);
154  2 assertNotNull(category);
155  2 assertEquals("/apple", category.getId());
156  2 assertEquals("Apple", category.getName());
157  2 assertEquals("apple", category.getTags());
158    }
159   
160    /**
161    * Tests that a level 3 category can be added with parent.
162    */
 
163  2 toggle public void testLevel3CategoryCanBeAddedWithParent() {
164  2 Category root = new Category("/", "/");
165  2 Category java = new Category("/java", "Java");
166  2 Category junit = new Category("/java/junit", "JUnit");
167  2 builder.addCategory(root);
168  2 builder.addCategory(java);
169  2 builder.addCategory(junit);
170  2 root.setTags("blog");
171  2 java.setTags("java");
172  2 junit.setTags("junit");
173   
174  2 Category category = (Category)builder.getRootCategory().getSubCategories().get(0);
175  2 assertNotNull(category);
176  2 assertEquals("/java", category.getId());
177  2 assertEquals("Java", category.getName());
178  2 assertEquals("java", category.getTags());
179  2 category = (Category)category.getSubCategories().get(0);
180  2 assertNotNull(category);
181  2 assertEquals("/java/junit", category.getId());
182  2 assertEquals("JUnit", category.getName());
183  2 assertEquals("junit", category.getTags());
184   
185  2 assertEquals(builder.getRootCategory(), java.getParent());
186  2 assertEquals(java, junit.getParent());
187    }
188   
189    /**
190    * Tests that a level 3 category can be added without parent.
191    */
 
192  2 toggle public void testLevel3CategoryCanBeAddedWithoutParent() {
193  2 Category junit = new Category("/java/junit", "JUnit");
194  2 builder.addCategory(junit);
195  2 junit.setTags("junit");
196   
197  2 Category java = (Category)builder.getRootCategory().getSubCategories().get(0);
198  2 assertNotNull(java);
199  2 assertEquals("/java", java.getId());
200  2 assertEquals("/java", java.getName());
201  2 assertEquals("", java.getTags());
202  2 junit = (Category)java.getSubCategories().get(0);
203  2 assertNotNull(junit);
204  2 assertEquals("/java/junit", junit.getId());
205  2 assertEquals("JUnit", junit.getName());
206  2 assertEquals("junit", junit.getTags());
207   
208  2 assertEquals(builder.getRootCategory(), java.getParent());
209  2 assertEquals(java, junit.getParent());
210    }
211   
212    /**
213    * Tests that a category can be added and retrieved.
214    */
 
215  2 toggle public void testCategoryCanBeAddedAndRetrieved() {
216  2 Category apple = new Category("/apple", "Apple");
217  2 builder.addCategory(apple);
218  2 apple.setTags("apple");
219  2 Category junit = new Category("/java/junit", "JUnit");
220  2 builder.addCategory(junit);
221  2 junit.setTags("junit");
222   
223  2 Category category = builder.getCategory("/apple");
224  2 assertEquals(apple, category);
225  2 category = builder.getCategory("/java/junit");
226  2 assertEquals(junit, category);
227    }
228   
229    }