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

File AbstractWikiParserTest.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

6
38
17
1
198
128
20
0.53
2.24
17
1.18

Classes

Class Line # Actions
AbstractWikiParserTest 37 38 0% 20 1
0.983606698.4%
 

Contributing tests

This file is covered by 134 tests. .

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.test;
21   
22    import java.io.StringReader;
23   
24    import org.xwiki.rendering.wikimodel.IWemListener;
25    import org.xwiki.rendering.wikimodel.IWikiParser;
26    import org.xwiki.rendering.wikimodel.IWikiPrinter;
27    import org.xwiki.rendering.wikimodel.WikiParameters;
28    import org.xwiki.rendering.wikimodel.WikiParserException;
29    import org.xwiki.rendering.wikimodel.xhtml.PrintListener;
30   
31    import junit.framework.TestCase;
32   
33    /**
34    * @version $Id: 43b421e2eb3020f67be8d6b34e7a66474cb73d1d $
35    * @since 4.0M1
36    */
 
37    public abstract class AbstractWikiParserTest extends TestCase
38    {
39    private boolean fOutputEnabled;
40   
41    private boolean fShowSections;
42   
43    private boolean supportImage;
44   
45    private boolean supportDownload;
46   
47    /**
48    * @param name
49    */
 
50  113 toggle public AbstractWikiParserTest(String name)
51    {
52  113 super(name);
53    }
54   
 
55  22 toggle public AbstractWikiParserTest(String name, boolean supportImage, boolean supportDownload)
56    {
57  22 super(name);
58   
59  22 this.supportImage = supportImage;
60  22 this.supportDownload = supportDownload;
61    }
62   
63    /**
64    * @param control
65    * @param test
66    */
 
67  1342 toggle protected void checkResults(String control, String test)
68    {
69  1342 if (control != null) {
70  1122 control = "<div class='wikimodel-document'>\n" + control
71    + "\n</div>\n";
72  1122 assertEquals(control, test);
73    }
74    }
75   
 
76  135 toggle protected void enableOutput(boolean enable)
77    {
78  135 fOutputEnabled = enable;
79    }
80   
81    /**
82    * @param buf
83    * @return
84    */
 
85  1337 toggle protected IWemListener newParserListener(final StringBuffer buf)
86    {
87  1337 IWikiPrinter printer = newPrinter(buf);
88  1337 IWemListener listener;
89  1337 if (!fShowSections) {
90  1329 listener = new PrintListener(printer, this.supportImage, this.supportDownload);
91    } else {
92  8 listener = new PrintListener(printer, this.supportImage, this.supportDownload)
93    {
 
94  24 toggle @Override
95    public void beginSection(int docLevel, int headerLevel,
96    WikiParameters params)
97    {
98  24 println("<section-" + docLevel + "-" + headerLevel + params
99    + ">");
100    }
101   
 
102  24 toggle @Override
103    public void beginSectionContent(int docLevel, int headerLevel,
104    WikiParameters params)
105    {
106  24 println("<sectionContent-" + docLevel + "-" + headerLevel
107    + params + ">");
108    }
109   
 
110  24 toggle @Override
111    public void endSection(int docLevel, int headerLevel,
112    WikiParameters params)
113    {
114  24 println("</section-" + docLevel + "-" + headerLevel + ">");
115    }
116   
 
117  24 toggle @Override
118    public void endSectionContent(int docLevel, int headerLevel,
119    WikiParameters params)
120    {
121  24 println("</sectionContent-" + docLevel + "-" + headerLevel
122    + ">");
123    }
124    };
125    }
126  1337 return listener;
127    }
128   
129    /**
130    * @param buf
131    * @return
132    */
 
133  1342 toggle protected IWikiPrinter newPrinter(final StringBuffer buf)
134    {
135  1342 IWikiPrinter printer = new IWikiPrinter()
136    {
 
137  12789 toggle public void print(String str)
138    {
139  12789 buf.append(str);
140    }
141   
 
142  6088 toggle public void println(String str)
143    {
144  6088 buf.append(str);
145  6088 buf.append("\n");
146    }
147    };
148  1342 return printer;
149    }
150   
151    protected abstract IWikiParser newWikiParser();
152   
 
153  2684 toggle protected void println(String str)
154    {
155  2684 if (fOutputEnabled) {
156  2684 System.out.println(str);
157    }
158    }
159   
 
160  135 toggle @Override
161    protected void setUp() throws Exception
162    {
163  135 super.setUp();
164  135 enableOutput(true);
165    }
166   
 
167  3 toggle protected void showSections(boolean b)
168    {
169  3 fShowSections = b;
170    }
171   
172    /**
173    * @param string
174    * @throws org.xwiki.rendering.wikimodel.WikiParserException
175    */
 
176  220 toggle protected void test(String string) throws WikiParserException
177    {
178  220 test(string, null);
179    }
180   
181    /**
182    * @param string
183    * @throws WikiParserException
184    */
 
185  1338 toggle protected void test(String string, String control)
186    throws WikiParserException
187    {
188  1338 println("==================================================");
189  1338 StringReader reader = new StringReader(string);
190  1338 IWikiParser parser = newWikiParser();
191  1338 final StringBuffer buf = new StringBuffer();
192  1338 IWemListener listener = newParserListener(buf);
193  1338 parser.parse(reader, listener);
194  1338 String test = buf.toString();
195  1338 println(test);
196  1338 checkResults(control, test);
197    }
198    }