1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.internal.syntax

File DefaultSyntaxFactoryTest.java

 

Code metrics

0
13
4
1
75
45
6
0.46
3.25
4
1.5

Classes

Class Line # Actions
DefaultSyntaxFactoryTest 35 13 0% 6 2
0.8823529588.2%
 

Contributing tests

This file is covered by 3 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.rendering.internal.syntax;
21   
22    import org.junit.Assert;
23    import org.junit.Before;
24    import org.junit.Test;
25    import org.xwiki.rendering.parser.ParseException;
26    import org.xwiki.rendering.syntax.Syntax;
27    import org.xwiki.rendering.syntax.SyntaxFactory;
28    import org.xwiki.test.jmock.AbstractComponentTestCase;
29   
30    /**
31    * Unit tests for {@link DefaultSyntaxFactory}.
32    *
33    * @version $Id: 35cf7eda24a2572dda54444d31cb85373a10a1a9 $
34    */
 
35    public class DefaultSyntaxFactoryTest extends AbstractComponentTestCase
36    {
37    private SyntaxFactory syntaxFactory;
38   
 
39  3 toggle @Before
40    public void configure() throws Exception
41    {
42  3 this.syntaxFactory = getComponentManager().getInstance(SyntaxFactory.class);
43    }
44   
 
45  1 toggle @Test
46    public void testCreateSyntaxFromSyntaxIdString() throws Exception
47    {
48  1 Syntax syntax = this.syntaxFactory.createSyntaxFromIdString("type/version");
49  1 Assert.assertEquals("type", syntax.getType().getId());
50  1 Assert.assertEquals("type", syntax.getType().getName());
51  1 Assert.assertEquals("version", syntax.getVersion());
52    }
53   
 
54  1 toggle @Test
55    public void testCreateSyntaxFromSyntaxIdStringWhenInvalid() throws Exception
56    {
57  1 try {
58  1 this.syntaxFactory.createSyntaxFromIdString("invalid");
59  0 Assert.fail("Should have thrown an exception");
60    } catch (ParseException expected) {
61  1 Assert.assertEquals("Invalid Syntax format [invalid]", expected.getMessage());
62    }
63    }
64   
 
65  1 toggle @Test
66    public void testCreateSyntaxFromSyntaxIdStringWhenNull() throws Exception
67    {
68  1 try {
69  1 this.syntaxFactory.createSyntaxFromIdString(null);
70  0 Assert.fail("Should have thrown an exception");
71    } catch (ParseException expected) {
72  1 Assert.assertEquals("The passed Syntax cannot be NULL", expected.getMessage());
73    }
74    }
75    }