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

File SpaceNormalizerContentAltererTest.java

 

Code metrics

0
23
4
1
122
54
4
0.17
5.75
4
1

Classes

Class Line # Actions
SpaceNormalizerContentAltererTest 40 23 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 15 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    * Tests the {@link org.xwiki.annotation.internal.content.SpaceNormalizerContentAlterer}.
35    *
36    * @version $Id: 3ee3067726e170f420875033f75936c410c3e85e $
37    * @since 2.3M1
38    */
39    @RunWith(Parameterized.class)
 
40    public class SpaceNormalizerContentAltererTest extends AbstractComponentTestCase
41    {
42    /**
43    * The initial String to alter.
44    */
45    private String initial;
46   
47    /**
48    * The expected altered string.
49    */
50    private String altered;
51   
52    /**
53    * The content alterer to test.
54    */
55    private ContentAlterer alterer;
56   
57    /**
58    * @param initial the original string
59    * @param altered the altered string after being whitespace filtered
60    */
 
61  15 toggle public SpaceNormalizerContentAltererTest(String initial, String altered)
62    {
63  15 this.initial = initial;
64  15 this.altered = altered;
65    }
66   
 
67  15 toggle @Override
68    public void setUp() throws Exception
69    {
70  15 super.setUp();
71  15 alterer = getComponentManager().getInstance(ContentAlterer.class, "space-normalizer");
72    }
73   
74    /**
75    * @return list of corpus files to instantiate tests for
76    */
 
77  1 toggle @Parameters
78    public static Collection<String[]> data()
79    {
80  1 Collection<String[]> params = new ArrayList<String[]>();
81    // unbreakable space
82  1 params.add(new String[] {"not\u00A0to be", "not to be"});
83    // tabs
84  1 params.add(new String[] {"to be or not\tto be", "to be or not to be"});
85    // commas, signs with regular spaces
86  1 params.add(new String[] {"roses, see I in her cheeks;", "roses, see I in her cheeks;"});
87    // new lines
88  1 params.add(new String[] {"eyes nothing\nlike the sun", "eyes nothing like the sun"});
89    // new line carriage return
90  1 params.add(new String[] {"eyes\n\rnothing", "eyes nothing"});
91    // multiple spaces one after the other
92  1 params.add(new String[] {"roses, see I in her cheeks;", "roses, see I in her cheeks;"});
93  1 params.add(new String[] {"roses, see I\u00A0 in her cheeks;", "roses, see I in her cheeks;"});
94  1 params.add(new String[] {"roses, see I\n \n in her cheeks;", "roses, see I in her cheeks;"});
95    // trim
96  1 params.add(new String[] {" roses, see I in her cheeks; ", "roses, see I in her cheeks;"});
97  1 params.add(new String[] {"\n\n\nroses, see I in her cheeks;", "roses, see I in her cheeks;"});
98  1 params.add(new String[] {"roses, see I in her cheeks;\n\n", "roses, see I in her cheeks;"});
99    // starting or ending with a non-breakable space
100  1 params.add(new String[] {"\u00A0roses, see I in her cheeks;", "roses, see I in her cheeks;"});
101  1 params.add(new String[] {"roses, see I in her cheeks;\u00A0", "roses, see I in her cheeks;"});
102   
103    // empty string should stay empty string
104  1 params.add(new String[] {"", ""});
105    // spaces only string should become empty string
106  1 params.add(new String[] {" \t\n", ""});
107   
108  1 return params;
109    }
110   
111    /**
112    * Tests that the content alterer filters correctly the characters out of the Strings.
113    */
 
114  15 toggle @Test
115    public void testFiltering()
116    {
117  15 AlteredContent alteredContent = alterer.alter(initial);
118  15 assertEquals(altered, alteredContent.getContent().toString());
119    }
120   
121    // TODO: test indexes to be in the right place
122    }