1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.wikimodel.util

File ListBuilderTest.java

 

Code metrics

0
37
9
1
210
172
9
0.24
4.11
9
1

Classes

Class Line # Actions
ListBuilderTest 28 37 0% 9 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.rendering.wikimodel.util;
21   
22    import junit.framework.TestCase;
23   
24    /**
25    * @version $Id: a48a261529dfcf1553497acaa0a4f74978d41b62 $
26    * @since 4.0M1
27    */
 
28    public class ListBuilderTest extends TestCase
29    {
30    /**
31    * @param name
32    */
 
33  1 toggle public ListBuilderTest(String name)
34    {
35  1 super(name);
36    }
37   
 
38  1 toggle public void testTwo() throws Exception
39    {
40  1 testTwo("a", "<A><a></a></A>");
41  1 testTwo("a\na", "<A><a></a><a></a></A>");
42  1 testTwo("a\n a", "<A><a><A><a></a></A></a></A>");
43  1 testTwo("a\n a\n a", "<A><a><A><a></a><a></a></A></a></A>");
44  1 testTwo("a\n a\n a\n a", "<A><a>"
45    + "<A>"
46    + "<a></a>"
47    + "<a></a>"
48    + "<a></a>"
49    + "</A>"
50    + "</a></A>");
51  1 testTwo("a\n b\n b\n b", "<A><a>"
52    + "<B>"
53    + "<b></b>"
54    + "<b></b>"
55    + "<b></b>"
56    + "</B>"
57    + "</a></A>");
58  1 testTwo("a\n b\n b\n b\na", "<A>"
59    + "<a>"
60    + "<B>"
61    + "<b></b>"
62    + "<b></b>"
63    + "<b></b>"
64    + "</B>"
65    + "</a>"
66    + "<a></a>"
67    + "</A>");
68  1 testTwo("a\nab\nabc\nabcd", "<A><a>"
69    + "<B><b>"
70    + "<C><c>"
71    + "<D><d></d></D>"
72    + "</c></C>"
73    + "</b></B>"
74    + "</a></A>");
75  1 testTwo("a\nab\nabc", "<A><a>"
76    + "<B><b>"
77    + "<C><c></c></C>"
78    + "</b></B>"
79    + "</a></A>");
80  1 testTwo(""
81    + " a\n"
82    + " a b\n"
83    + " a c\n"
84    + " a c d\n"
85    + " e"
86    + ""
87    + ""
88    + ""
89    + ""
90    + "", "<A><a>"
91    + "<B><b></b></B>"
92    + "<C><c>"
93    + "<D><d></d></D>"
94    + "</c></C>"
95    + "</a></A>"
96    + "<E><e></e></E>");
97   
98  1 testTwo("a\n b", "<A><a><B><b></b></B></a></A>");
99  1 testTwo("a\nab", "<A><a><B><b></b></B></a></A>");
100  1 testTwo("a\n ", "<A><a></a></A>");
101  1 testTwo(" ", "");
102  1 testTwo("", "");
103  1 testTwo(" ", "");
104  1 testTwo(" a", "<A><a></a></A>");
105  1 testTwo(" a \n ", "<A><a></a></A>");
106  1 testTwo(""
107    + " a\n"
108    + " b\n"
109    + " c\n"
110    + " d\n"
111    + " e"
112    + ""
113    + ""
114    + ""
115    + ""
116    + "", "<A><a>"
117    + "<B><b></b></B>"
118    + "<C><c>"
119    + "<D><d></d></D>"
120    + "</c></C>"
121    + "</a></A>"
122    + "<E><e></e></E>");
123  1 testTwo(""
124    + "a\n"
125    + "ab\n"
126    + "ac\n"
127    + "acd\n"
128    + "e"
129    + ""
130    + ""
131    + ""
132    + ""
133    + "", "<A><a>"
134    + "<B><b></b></B>"
135    + "<C><c>"
136    + "<D><d></d></D>"
137    + "</c></C>"
138    + "</a></A>"
139    + "<E><e></e></E>");
140  1 testTwo(""
141    + " a\n"
142    + " a b\n"
143    + " a c\n"
144    + " a c d\n"
145    + " e"
146    + ""
147    + ""
148    + ""
149    + ""
150    + "", "<A><a>"
151    + "<B><b></b></B>"
152    + "<C><c>"
153    + "<D><d></d></D>"
154    + "</c></C>"
155    + "</a></A>"
156    + "<E><e></e></E>");
157   
158  1 testTwo("" + " a\n" + " b\n" + " c\n" + "cd\n" + "", ""
159    + "<A><a></a></A>"
160    + "<B><b></b></B>"
161    + "<C><c>"
162    + "<D><d></d></D>"
163    + "</c></C>");
164    }
165   
 
166  22 toggle private void testTwo(String string, String control)
167    {
168  22 final StringBuffer buf = new StringBuffer();
169  22 IListListener listener = new IListListener()
170    {
 
171  59 toggle public void beginRow(char treeType, char rowType)
172    {
173  59 openTag(rowType);
174    }
175   
 
176  50 toggle public void beginTree(char type)
177    {
178  50 openTag(Character.toUpperCase(type));
179    }
180   
 
181  109 toggle private void closeTag(char ch)
182    {
183  109 buf.append("</").append(ch).append(">");
184    }
185   
 
186  59 toggle public void endRow(char treeType, char rowType)
187    {
188  59 closeTag(rowType);
189    }
190   
 
191  50 toggle public void endTree(char type)
192    {
193  50 closeTag(Character.toUpperCase(type));
194    }
195   
 
196  109 toggle private void openTag(char str)
197    {
198  109 buf.append("<").append(str).append(">");
199    }
200    };
201  22 ListBuilder builder = new ListBuilder(listener);
202  22 String[] lines = string.split("\n");
203  22 for (String s : lines) {
204  64 builder.alignContext(s);
205    }
206  22 builder.alignContext("");
207    // builder.finish();
208  22 assertEquals(control, buf.toString());
209    }
210    }