Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
62   126   6   10,33
0   78   0,1   6
6     1  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  StringUtilsTest       Line # 41 62 0% 6 0 100% 1.0
 
  (12)
 
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.util;
33   
34    import junit.framework.TestCase;
35   
36    /**
37    * Tests for the utilities in the StringUtils class.
38    *
39    * @author Simon Brown
40    */
 
41    public class StringUtilsTest extends TestCase {
42   
 
43  2 toggle public void testTransformHTML() {
44  2 assertNull(StringUtils.transformHTML(null));
45  2 assertEquals("Here is some text", StringUtils.transformHTML("Here is some text"));
46  2 assertEquals("Here is a &lt; symbol", StringUtils.transformHTML("Here is a < symbol"));
47  2 assertEquals("Here is a &gt; symbol", StringUtils.transformHTML("Here is a > symbol"));
48  2 assertEquals("Here is a &amp; symbol", StringUtils.transformHTML("Here is a & symbol"));
49  2 assertEquals("&lt;a href=&quot;http://www.google.com&quot;&gt;Google&lt;/a&gt;", StringUtils.transformHTML("<a href=\"http://www.google.com\">Google</a>"));
50    }
51   
 
52  2 toggle public void testTransformToHTMLSubset() {
53  2 assertNull(StringUtils.transformToHTMLSubset(null));
54  2 assertEquals("Here is some text", StringUtils.transformToHTMLSubset("Here is some text"));
55  2 assertEquals("Here is a &lt; symbol", StringUtils.transformToHTMLSubset("Here is a &amp;lt; symbol"));
56  2 assertEquals("Here is a &lt; symbol", StringUtils.transformToHTMLSubset("Here is a &lt; symbol"));
57  2 assertEquals("Here is a &gt; symbol", StringUtils.transformToHTMLSubset("Here is a &amp;gt; symbol"));
58  2 assertEquals("Here is a &gt; symbol", StringUtils.transformToHTMLSubset("Here is a &gt; symbol"));
59  2 assertEquals("Here is a <b> tag", StringUtils.transformToHTMLSubset("Here is a &lt;b&gt; tag"));
60  2 assertEquals("Here is a <strong> tag", StringUtils.transformToHTMLSubset("Here is a &lt;strong&gt; tag"));
61  2 assertEquals("Here is a <i> tag", StringUtils.transformToHTMLSubset("Here is a &lt;i&gt; tag"));
62  2 assertEquals("Here is a <em> tag", StringUtils.transformToHTMLSubset("Here is a &lt;em&gt; tag"));
63  2 assertEquals("Here is a <p> tag", StringUtils.transformToHTMLSubset("Here is a &lt;p&gt; tag"));
64  2 assertEquals("Here is a </p> tag", StringUtils.transformToHTMLSubset("Here is a &lt;/p&gt; tag"));
65  2 assertEquals("Here is a <br /> tag", StringUtils.transformToHTMLSubset("Here is a &lt;br&gt; tag"));
66  2 assertEquals("Here is a <br /> tag", StringUtils.transformToHTMLSubset("Here is a &lt;br/&gt; tag"));
67  2 assertEquals("Here is a <br /> tag", StringUtils.transformToHTMLSubset("Here is a &lt;br /&gt; tag"));
68  2 assertEquals("Here is a <pre> tag", StringUtils.transformToHTMLSubset("Here is a &lt;pre&gt; tag"));
69  2 assertEquals("Here is a </pre> tag", StringUtils.transformToHTMLSubset("Here is a &lt;/pre&gt; tag"));
70  2 assertEquals("Here is a <a href=\"http://www.google.com\">link</a> to Google", StringUtils.transformToHTMLSubset("Here is a &lt;a href=&quot;http://www.google.com&quot;&gt;link&lt;/a&gt; to Google"));
71  2 assertEquals("Here is a <a href=\"http://www.google.com\">link</a> to Google and another <a href=\"http://www.google.com\">link</a>", StringUtils.transformToHTMLSubset("Here is a &lt;a href=&quot;http://www.google.com&quot;&gt;link&lt;/a&gt; to Google and another &lt;a href=&quot;http://www.google.com&quot;&gt;link&lt;/a&gt;"));
72  2 assertEquals("Here is a <a href='http://www.google.com'>link</a> to Google", StringUtils.transformToHTMLSubset("Here is a &lt;a href='http://www.google.com'&gt;link&lt;/a&gt; to Google"));
73  2 assertEquals("Here is a <a href='http://www.google.com'>link</a> to Google and another <a href='http://www.google.com'>link</a>", StringUtils.transformToHTMLSubset("Here is a &lt;a href='http://www.google.com'&gt;link&lt;/a&gt; to Google and another &lt;a href='http://www.google.com'&gt;link&lt;/a&gt;"));
74  2 assertEquals("Here is a <a href=\"http://www.google.com\">link</a> to Google", StringUtils.transformToHTMLSubset("Here is a &lt;a href=&quot;http://www.google.com&quot; target=&quot;_blank&quot;&gt;link&lt;/a&gt; to Google"));
75  2 assertEquals("Here is a &lt;script&gt; tag", StringUtils.transformToHTMLSubset("Here is a &lt;script&gt; tag"));
76  2 assertEquals("Here is a <blockquote> tag", StringUtils.transformToHTMLSubset("Here is a &lt;blockquote&gt; tag"));
77  2 assertEquals("Here is a </blockquote> tag", StringUtils.transformToHTMLSubset("Here is a &lt;/blockquote&gt; tag"));
78  2 assertEquals("Here is a <a href=\"mailto:somebody@somedomain.com\">mail link</a>", StringUtils.transformToHTMLSubset("Here is a &lt;a href=&quot;mailto:somebody@somedomain.com&quot;&gt;mail link&lt;/a&gt;"));
79  2 assertEquals("Here is a &#8217; character", StringUtils.transformToHTMLSubset("Here is a &amp;#8217; character"));
80  2 assertEquals("Here is a &quot; symbol", StringUtils.transformToHTMLSubset("Here is a &amp;quot; symbol"));
81  2 assertEquals("&uacute;", StringUtils.transformToHTMLSubset("&amp;uacute;"));
82  2 assertEquals("see contracts as &quot;fly-by-night&quot; sorts", StringUtils.transformToHTMLSubset("see contracts as &amp;quot;fly-by-night&amp;quot; sorts"));
83  2 assertEquals("Here is a <sup> tag", StringUtils.transformToHTMLSubset("Here is a &lt;sup&gt; tag"));
84  2 assertEquals("Here is a <sub> tag", StringUtils.transformToHTMLSubset("Here is a &lt;sub&gt; tag"));
85    // validating URL schemes
86  2 assertEquals("Here is a <a href=\"https://www.google.com\">link</a> to Google", StringUtils.transformToHTMLSubset("Here is a &lt;a href=&quot;https://www.google.com&quot;&gt;link&lt;/a&gt; to Google"));
87  2 assertEquals("Here is a <a href=\"ftp://www.google.com\">link</a> to Google", StringUtils.transformToHTMLSubset("Here is a &lt;a href=&quot;ftp://www.google.com&quot;&gt;link&lt;/a&gt; to Google"));
88    // block javascript
89  2 assertEquals("Here is a <a href=\"\">link</a> to Google", StringUtils.transformToHTMLSubset("Here is a &lt;a href=&quot;javascript:alert('Hi')&quot;&gt;link&lt;/a&gt; to Google"));
90    }
91   
 
92  2 toggle public void testFilterNewLines() {
93  2 assertNull(StringUtils.filterNewlines(null));
94  2 assertEquals("Here is some text", StringUtils.filterNewlines("Here is some text"));
95  2 assertEquals("Line 1\n", StringUtils.filterNewlines("Line 1\r\n"));
96  2 assertEquals("Line 1\nLine2", StringUtils.filterNewlines("Line 1\r\nLine2"));
97    }
98   
 
99  2 toggle public void testFilterHTML() {
100  2 assertEquals("Here is some text.", StringUtils.filterHTML("Here is <!-- <rdf>...</rdf> -->some text."));
101  2 assertEquals("Here is some text.", StringUtils.filterHTML("Here is <!-- <rdf/> -->some text."));
102  2 assertEquals("Here is some text.", StringUtils.filterHTML("<b>Here</b> is <i>some</i> text."));
103  2 assertEquals("Here is a link.", StringUtils.filterHTML("Here is <a href=\"http://www.google.com\">a link</a>."));
104  2 assertEquals("Here is a link.", StringUtils.filterHTML("Here is <a \nhref=\"http://www.google.com\">a link</a>."));
105  2 assertEquals("Here is some text", StringUtils.filterHTML("Here is &lt;some&gt; text"));
106    }
107   
 
108  2 toggle public void testStripScriptTags() {
109  2 assertEquals("some text", StringUtils.stripScriptTags("some <script>alert(1)</script>text"));
110  2 assertEquals("some text", StringUtils.stripScriptTags("some <script >alert(1)</script>text"));
111  2 assertEquals("some text", StringUtils.stripScriptTags("some <script >alert(1)</script >text"));
112  2 assertEquals("some text", StringUtils.stripScriptTags("some <script language=\"JavaScript\">alert(1)</script >text"));
113  2 assertEquals("some text", StringUtils.stripScriptTags("some <script src=\"something.js\"/>text"));
114    }
115   
116   
 
117  2 toggle public void testUnescapeHTMLEntities() {
118  2 assertEquals("\u00A0", StringUtils.unescapeHTMLEntities("&nbsp;"));
119  2 assertEquals("\u00A0\u00A0nbsp\u00A0\u00A0", StringUtils.unescapeHTMLEntities("&nbsp;&nbsp;nbsp&nbsp;&nbsp;"));
120  2 assertEquals("\u00E7", StringUtils.unescapeHTMLEntities("&ccedil;"));
121  2 assertEquals("\u00C7", StringUtils.unescapeHTMLEntities("&Ccedil;"));
122  2 assertEquals("\u03BC\u03BD\u039E", StringUtils.unescapeHTMLEntities("&mu;&nu;&Xi;"));
123  2 assertEquals("Seven \u00D0 and eight \u00A3 \u00E7 5 \u2666", StringUtils.unescapeHTMLEntities("Seven &ETH; and eight &pound; &ccedil; 5 &diams;"));
124    }
125   
126    }