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

File WhiteSpaceContentAltererTest.java

 

Code metrics

0
13
4
1
101
44
4
0.31
3.25
4
1

Classes

Class Line # Actions
WhiteSpaceContentAltererTest 38 13 0% 4 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    package org.xwiki.annotation.content;
21   
22    import static org.junit.Assert.assertEquals;
23   
24    import java.util.ArrayList;
25    import java.util.Collection;
26   
27    import org.junit.Test;
28    import org.junit.runner.RunWith;
29    import org.junit.runners.Parameterized;
30    import org.junit.runners.Parameterized.Parameters;
31    import org.xwiki.test.jmock.AbstractComponentTestCase;
32   
33    /**
34    * @version $Id: 86b31ce4f20844fa4fdf5527ad3d93c2f026b338 $
35    * @since 2.3M1
36    */
37    @RunWith(Parameterized.class)
 
38    public class WhiteSpaceContentAltererTest extends AbstractComponentTestCase
39    {
40    /**
41    * The initial String to alter.
42    */
43    private String initial;
44   
45    /**
46    * The expected altered string.
47    */
48    private String altered;
49   
50    /**
51    * The content alterer to test.
52    */
53    private ContentAlterer alterer;
54   
55    /**
56    * @param initial the original string
57    * @param altered the altered string after being whitespace filtered
58    */
 
59  5 toggle public WhiteSpaceContentAltererTest(String initial, String altered)
60    {
61  5 this.initial = initial;
62  5 this.altered = altered;
63    }
64   
 
65  5 toggle @Override
66    public void setUp() throws Exception
67    {
68  5 super.setUp();
69  5 alterer = getComponentManager().getInstance(ContentAlterer.class, "whitespace");
70    }
71   
72    /**
73    * @return list of corpus files to instantiate tests for
74    */
 
75  1 toggle @Parameters
76    public static Collection<String[]> data()
77    {
78  1 Collection<String[]> params = new ArrayList<String[]>();
79    // unbreakable space
80  1 params.add(new String[] {"not\u00A0to be", "nottobe"});
81    // tabs
82  1 params.add(new String[] {"to be or not\tto be", "tobeornottobe"});
83    // commas, signs with regular spaces
84  1 params.add(new String[] {"roses, see I in her cheeks;", "roses,seeIinhercheeks;"});
85    // new lines
86  1 params.add(new String[] {"eyes nothing\nlike the sun", "eyesnothinglikethesun"});
87    // new line carriage return
88  1 params.add(new String[] {"eyes\n\rnothing", "eyesnothing"});
89  1 return params;
90    }
91   
92    /**
93    * Tests that the content alterer filters correctly the characters out of the Strings.
94    */
 
95  5 toggle @Test
96    public void testFiltering()
97    {
98  5 AlteredContent alteredContent = alterer.alter(initial);
99  5 assertEquals(altered, alteredContent.getContent().toString());
100    }
101    }