1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.refactoring.splitter.criterion.naming

File HeadingNameNamingCriterionTest.java

 

Code metrics

0
19
1
1
81
41
1
0.05
19
1
1

Classes

Class Line # Actions
HeadingNameNamingCriterionTest 38 19 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

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.refactoring.splitter.criterion.naming;
21   
22    import java.io.StringReader;
23   
24    import org.xwiki.refactoring.internal.AbstractRefactoringTestCase;
25    import org.xwiki.rendering.block.Block;
26    import org.xwiki.rendering.block.XDOM;
27    import org.xwiki.rendering.syntax.Syntax;
28    import org.xwiki.rendering.renderer.BlockRenderer;
29    import org.junit.Assert;
30    import org.junit.Test;
31   
32    /**
33    * Test case for {@link HeadingNameNamingCriterion}.
34    *
35    * @version $Id: e3538e510fa97df0413a7a42e3d1062475487866 $
36    * @since 1.9M1
37    */
 
38    public class HeadingNameNamingCriterionTest extends AbstractRefactoringTestCase
39    {
40    /**
41    * Tests document names generated.
42    *
43    * @throws Exception
44    */
 
45  1 toggle @Test
46    public void testDocumentNamesGeneration() throws Exception
47    {
48  1 XDOM xdom = xwikiParser.parse(new StringReader("=Heading="));
49  1 BlockRenderer plainSyntaxBlockRenderer =
50    getComponentManager().getInstance(BlockRenderer.class, Syntax.PLAIN_1_0.toIdString());
51  1 NamingCriterion namingCriterion =
52    new HeadingNameNamingCriterion("Test.Test", docBridge, plainSyntaxBlockRenderer, false);
53  1 Block sectionBlock = xdom.getChildren().get(0);
54    // Test normal heading-name naming
55  1 Assert.assertEquals("Test.Heading", namingCriterion.getDocumentName(new XDOM(sectionBlock.getChildren())));
56    // Test name clash resolution
57  1 Assert.assertEquals("Test.Heading-1", namingCriterion.getDocumentName(new XDOM(sectionBlock.getChildren())));
58    // Test heading text cleaning (replacing)
59  1 xdom = xwikiParser.parse(new StringReader("= This-Very.Weird:Heading! ="));
60  1 sectionBlock = xdom.getChildren().get(0);
61  1 Assert.assertEquals("Test.This-Very-Weird-Heading!",
62    namingCriterion.getDocumentName(new XDOM(sectionBlock.getChildren())));
63    // Test heading text cleaning (stripping)
64  1 xdom = xwikiParser.parse(new StringReader("= This?Is@A/Very#Weird~Heading ="));
65  1 sectionBlock = xdom.getChildren().get(0);
66  1 Assert.assertEquals("Test.ThisIsAVeryWeirdHeading",
67    namingCriterion.getDocumentName(new XDOM(sectionBlock.getChildren())));
68    // Test page name truncation.
69  1 xdom = xwikiParser.parse(new StringReader("=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
70    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
71    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa="));
72  1 sectionBlock = xdom.getChildren().get(0);
73  1 Assert.assertEquals(255, namingCriterion.getDocumentName(new XDOM(sectionBlock.getChildren())).length());
74    // Test fallback operation
75  1 Assert.assertEquals("Test.Test-1", namingCriterion.getDocumentName(xdom));
76    // Test fallback operation under empty heading names
77  1 xdom = xwikiParser.parse(new StringReader("= ="));
78  1 sectionBlock = xdom.getChildren().get(0);
79  1 Assert.assertEquals("Test.Test-2", namingCriterion.getDocumentName(new XDOM(sectionBlock.getChildren())));
80    }
81    }