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

File TreeBuilder1Test.java

 

Code metrics

0
24
10
1
117
65
10
0.42
2.4
10
1

Classes

Class Line # Actions
TreeBuilder1Test 30 24 0% 10 1
0.970588297.1%
 

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.tmp;
21   
22    import org.xwiki.rendering.wikimodel.util.tmp.TreeBuilder1.ITreeBuilderListener;
23   
24    import junit.framework.TestCase;
25   
26    /**
27    * @version $Id: 88ba647e12023f29c1adf6050118135a202ae5f3 $
28    * @since 4.0M1
29    */
 
30    public class TreeBuilder1Test extends TestCase
31    {
32    final StringBuffer fBuf = new StringBuffer();
33   
34    TreeBuilder1<String> fBuilder;
35   
36    /**
37    *
38    */
 
39  0 toggle public TreeBuilder1Test()
40    {
41    }
42   
43    /**
44    * @param name
45    */
 
46  1 toggle public TreeBuilder1Test(String name)
47    {
48  1 super(name);
49    }
50   
51    /**
52    * @param control
53    */
 
54  10 toggle private void check(String control)
55    {
56  10 assertEquals(control, fBuf.toString());
57  10 fBuf.delete(0, fBuf.length());
58    }
59   
 
60  1 toggle @Override
61    protected void setUp() throws Exception
62    {
63  1 ITreeBuilderListener<String> listener = new ITreeBuilderListener<String>()
64    {
 
65  7 toggle public void beginItem(int depth, String data)
66    {
67  7 fBuf.append("<" + data + ">");
68    }
69   
 
70  3 toggle public void beginLevel(int depth, String prevBegin)
71    {
72  3 fBuf.append("<level>");
73    }
74   
 
75  7 toggle public void endItem(int depth, String data)
76    {
77  7 fBuf.append("</" + data + ">");
78    }
79   
 
80  3 toggle public void endLevel(int i, String prevBegin)
81    {
82  3 fBuf.append("</level>");
83    }
84    };
85  1 fBuilder = new TreeBuilder1<String>(listener);
86    }
87   
 
88  1 toggle public void test() throws Exception
89    {
90  1 test(0, "a", "<level><a>");
91  1 test(30, "b", "<level><b>");
92  1 test(10, "c", "</b><c>");
93   
94  1 test(30, "d", "<level><d>");
95  1 test(15, "e", "</d><e>");
96  1 test(8, "f", "</e></level></c><f>");
97  1 test(8, "g", "</f><g>");
98   
99  1 fBuilder.trim(10);
100  1 check("");
101  1 fBuilder.trim(8, false);
102  1 check("");
103  1 fBuilder.finish();
104  1 check("</g></level></a></level>");
105    }
106   
107    /**
108    * @param value
109    * @param control
110    * @param string
111    */
 
112  7 toggle private void test(int value, String data, String control)
113    {
114  7 fBuilder.align(value, data);
115  7 check(control);
116    }
117    }