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

File BlockMatcherConverterTest.java

 

Code metrics

0
13
3
1
72
39
4
0.31
4.33
3
1.33

Classes

Class Line # Actions
BlockMatcherConverterTest 36 13 0% 4 1
0.937593.8%
 

Contributing tests

This file is covered by 2 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.block;
21   
22    import org.junit.Assert;
23    import org.junit.Test;
24    import org.xwiki.properties.converter.ConversionException;
25    import org.xwiki.rendering.block.SpaceBlock;
26    import org.xwiki.rendering.block.WordBlock;
27    import org.xwiki.rendering.block.match.BlockMatcher;
28    import org.xwiki.rendering.block.match.ClassBlockMatcher;
29   
30    /**
31    * Unit tests for {@link org.xwiki.rendering.internal.block.BlockMatcherConverter}.
32    *
33    * @version $Id: 9a7bbd2da80e4fcc459e168bb90456fdd5c75c1a $
34    * @since 6.1RC1
35    */
 
36    public class BlockMatcherConverterTest
37    {
38    private BlockMatcherConverter converter = new BlockMatcherConverter();
39   
 
40  1 toggle @Test
41    public void testConvertFromString()
42    {
43  1 BlockMatcher wordMatcher =
44    this.converter.convert(BlockMatcher.class, "class:org.xwiki.rendering.block.WordBlock");
45  1 Assert.assertTrue(wordMatcher instanceof ClassBlockMatcher);
46    // any better check that this matcher
47  1 Assert.assertTrue(wordMatcher.match(new WordBlock("test")));
48  1 Assert.assertFalse(wordMatcher.match(new SpaceBlock()));
49   
50  1 BlockMatcher wordMatcher2 = this.converter.convert(BlockMatcher.class, "class:WordBlock");
51  1 Assert.assertTrue(wordMatcher2 instanceof ClassBlockMatcher);
52    }
53   
 
54  1 toggle @Test
55    public void testConvertFromStringFailures()
56    {
57  1 assertConversionException("class:does.not.exist.FantasyBlock");
58  1 assertConversionException("class:java.lang.String");
59  1 assertConversionException("class:FantasyBlock");
60  1 assertConversionException("macro:box"); // at least yet
61    }
62   
 
63  4 toggle private void assertConversionException(String input)
64    {
65  4 try {
66  4 this.converter.convert(BlockMatcher.class, input);
67  0 Assert.fail("should not parse " + input);
68    } catch (ConversionException e) {
69    // expected
70    }
71    }
72    }