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

File MacroErrorManagerTest.java

 

Code metrics

0
11
3
1
83
52
3
0.27
3.67
3
1

Classes

Class Line # Actions
MacroErrorManagerTest 49 11 0% 3 0
1.0100%
 

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.transformation.macro;
21   
22    import java.util.Arrays;
23    import java.util.Collections;
24   
25    import org.junit.Assert;
26    import org.junit.Rule;
27    import org.junit.Test;
28    import org.xwiki.rendering.block.FormatBlock;
29    import org.xwiki.rendering.block.GroupBlock;
30    import org.xwiki.rendering.block.MacroBlock;
31    import org.xwiki.rendering.block.ParagraphBlock;
32    import org.xwiki.rendering.block.WordBlock;
33    import org.xwiki.rendering.block.XDOM;
34    import org.xwiki.rendering.internal.util.DefaultErrorBlockGenerator;
35    import org.xwiki.rendering.listener.Format;
36    import org.xwiki.rendering.util.ErrorBlockGenerator;
37    import org.xwiki.test.annotation.ComponentList;
38    import org.xwiki.test.mockito.MockitoComponentManagerRule;
39   
40    /**
41    * Unit tests for {@link MacroErrorManager}.
42    *
43    * @version $Id: a5de00f9de8e743425efad4a1ea55da336cdf9bc $
44    * @since 4.3M2
45    */
46    @ComponentList({
47    DefaultErrorBlockGenerator.class
48    })
 
49    public class MacroErrorManagerTest
50    {
51    @Rule
52    public MockitoComponentManagerRule componentManager = new MockitoComponentManagerRule();
53   
 
54  1 toggle @Test
55    public void containsErrorWhenNoError() throws Exception
56    {
57  1 MacroErrorManager errorManager =
58    new MacroErrorManager(this.componentManager.getInstance(ErrorBlockGenerator.class));
59  1 XDOM xdom = new XDOM(Arrays.asList(new ParagraphBlock(Arrays.asList(new WordBlock("test")))));
60  1 Assert.assertFalse(errorManager.containsError(xdom));
61    }
62   
 
63  1 toggle @Test
64    public void containsErrorWhenNoErrorButGroupAndFormatBlocks() throws Exception
65    {
66  1 MacroErrorManager errorManager =
67    new MacroErrorManager(this.componentManager.getInstance(ErrorBlockGenerator.class));
68  1 XDOM xdom = new XDOM(Arrays.asList(new GroupBlock(Arrays.asList(
69    new FormatBlock(Arrays.asList(new WordBlock("test")), Format.BOLD)))));
70  1 Assert.assertFalse(errorManager.containsError(xdom));
71    }
72   
 
73  1 toggle @Test
74    public void containsErrorWhenInlineMacroError() throws Exception
75    {
76  1 MacroErrorManager errorManager =
77    new MacroErrorManager(this.componentManager.getInstance(ErrorBlockGenerator.class));
78  1 MacroBlock macroBlock = new MacroBlock("testmacro", Collections.emptyMap(), true);
79  1 XDOM xdom = new XDOM(Arrays.asList(macroBlock));
80  1 errorManager.generateError(macroBlock, "test message", "test description");
81  1 Assert.assertTrue(errorManager.containsError(xdom));
82    }
83    }