1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.rendering.macro.toc

File TocMacroTest.java

 

Code metrics

0
12
4
1
102
66
5
0.42
3
4
1.25

Classes

Class Line # Actions
TocMacroTest 58 12 0% 5 1
0.937593.8%
 

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.macro.toc;
21   
22    import java.util.Collections;
23   
24    import org.junit.Before;
25    import org.junit.Rule;
26    import org.junit.Test;
27    import org.xwiki.properties.BeanManager;
28    import org.xwiki.properties.PropertyException;
29    import org.xwiki.properties.internal.DefaultBeanManager;
30    import org.xwiki.properties.internal.DefaultConverterManager;
31    import org.xwiki.properties.internal.converter.ConvertUtilsConverter;
32    import org.xwiki.properties.internal.converter.EnumConverter;
33    import org.xwiki.rendering.internal.macro.toc.TocMacro;
34    import org.xwiki.rendering.listener.reference.DocumentResourceReference;
35    import org.xwiki.rendering.macro.MacroExecutionException;
36    import org.xwiki.rendering.transformation.MacroTransformationContext;
37    import org.xwiki.rendering.wiki.WikiModel;
38    import org.xwiki.rendering.wiki.WikiModelException;
39    import org.xwiki.test.annotation.ComponentList;
40    import org.xwiki.test.mockito.MockitoComponentMockingRule;
41   
42    import static org.junit.Assert.assertEquals;
43    import static org.junit.Assert.fail;
44    import static org.mockito.Mockito.mock;
45    import static org.mockito.Mockito.when;
46   
47    /**
48    * Validate {@link TocMacro}.
49    *
50    * @version $Id: 85e8e44530e1211f0db4cbfa5ca8871f14904c53 $
51    */
52    @ComponentList({
53    DefaultBeanManager.class,
54    DefaultConverterManager.class,
55    EnumConverter.class,
56    ConvertUtilsConverter.class
57    })
 
58    public class TocMacroTest
59    {
60    @Rule
61    public MockitoComponentMockingRule<TocMacro> mocker = new MockitoComponentMockingRule<TocMacro>(TocMacro.class);
62   
63    private BeanManager beanManager;
64   
 
65  3 toggle @Before
66    public void setUp() throws Exception
67    {
68  3 this.beanManager = this.mocker.getInstance(BeanManager.class);
69    }
70   
 
71  1 toggle @Test(expected = PropertyException.class)
72    public void testStartTooLow() throws PropertyException
73    {
74  1 this.beanManager.populate(new TocMacroParameters(), Collections.singletonMap("start", "0"));
75    }
76   
 
77  1 toggle @Test(expected = PropertyException.class)
78    public void testDepthTooLow() throws PropertyException
79    {
80  1 this.beanManager.populate(new TocMacroParameters(), Collections.singletonMap("depth", "0"));
81    }
82   
 
83  1 toggle @Test
84    public void executeWhenXDOMRetrievalFailed() throws Exception
85    {
86  1 TocMacroParameters parameters = new TocMacroParameters();
87  1 parameters.setReference("reference");
88  1 WikiModel wikiModel = this.mocker.getInstance(WikiModel.class);
89  1 when(wikiModel.getXDOM(new DocumentResourceReference("reference"))).thenThrow(new WikiModelException("error"));
90   
91  1 MacroTransformationContext mtc = mock(MacroTransformationContext.class);
92   
93  1 try {
94  1 this.mocker.getComponentUnderTest().execute(parameters, null, mtc);
95  0 fail("Should have thrown an exception here");
96    } catch (MacroExecutionException expected) {
97  1 assertEquals("Failed to get XDOM for [Typed = [true] Type = [doc] Reference = [reference]]",
98    expected.getMessage());
99    }
100   
101    }
102    }