1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.velocity.tools

File URLToolTest.java

 

Code metrics

0
16
5
1
82
47
5
0.31
3.2
5
1

Classes

Class Line # Actions
URLToolTest 37 16 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 5 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   
21    package org.xwiki.velocity.tools;
22   
23    import java.util.Arrays;
24    import java.util.Collections;
25    import java.util.Map;
26   
27    import org.junit.Test;
28   
29    import static org.junit.Assert.*;
30   
31    /**
32    * Unit tests for {@link URLTool}.
33    *
34    * @version $Id: efa3993d70331ab622e07a6dbfd884e466781a46 $
35    * @since 6.3M1
36    */
 
37    public class URLToolTest
38    {
39    private URLTool tool = new URLTool();
40   
 
41  1 toggle @Test
42    public void testSimpleUrlParse()
43    {
44  1 Map<String, ?> query = tool.parseQuery("a=b%26c");
45  1 assertEquals("should have one parameter", Collections.singleton("a"), query.keySet());
46  1 assertEquals("should have one parameter value", Collections.singletonList("b&c"), query.get("a"));
47    }
48   
 
49  1 toggle @Test
50    public void testUrlParseMultipleValues()
51    {
52  1 Map<String, ?> query = tool.parseQuery("a=b+c&a=b%3Dc&ab=a+%26+b");
53  1 assertEquals("should have two parameter", 2, query.size());
54  1 assertEquals("should have one parameter value for ab", Collections.singletonList("a & b"), query.get("ab"));
55  1 assertEquals("should have two parameter values for a", Arrays.asList(new String[] {"b c", "b=c"}),
56    query.get("a"));
57    }
58   
 
59  1 toggle @Test
60    public void testInvalidUrlParse()
61    {
62  1 Map<String, ?> query = tool.parseQuery("a=b ' onclick='foo");
63  1 assertEquals("should have one parameter", Collections.singleton("a"), query.keySet());
64  1 assertEquals("should have one parameter", Collections.singletonList("b ' onclick='foo"), query.get("a"));
65    }
66   
 
67  1 toggle @Test
68    public void testHandleNull()
69    {
70  1 Map<String, ?> query = tool.parseQuery(null);
71  1 assertNotNull("null query results in empty map", query);
72  1 assertTrue("null query results in empty map", query.isEmpty());
73    }
74   
 
75  1 toggle @Test
76    public void preserveParameterOrder()
77    {
78  1 EscapeTool escapeTool = new EscapeTool();
79  1 String queryString = "x=5&x=4&r=3&a=2";
80  1 assertEquals(queryString, escapeTool.url(tool.parseQuery(queryString)));
81    }
82    }