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

File DocumentTableBlockDataSourceTest.java

 

Code metrics

0
12
1
1
73
39
1
0.08
12
1
1

Classes

Class Line # Actions
DocumentTableBlockDataSourceTest 45 12 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.rendering.internal.macro.chart.source.table;
21   
22    import java.util.Collections;
23   
24    import org.junit.Assert;
25    import org.junit.Rule;
26    import org.junit.Test;
27    import org.xwiki.bridge.DocumentAccessBridge;
28    import org.xwiki.model.reference.DocumentReference;
29    import org.xwiki.model.reference.DocumentReferenceResolver;
30    import org.xwiki.rendering.block.Block;
31    import org.xwiki.rendering.block.MacroBlock;
32    import org.xwiki.rendering.block.MetaDataBlock;
33    import org.xwiki.rendering.block.match.BlockMatcher;
34    import org.xwiki.rendering.listener.MetaData;
35    import org.xwiki.test.mockito.MockitoComponentMockingRule;
36   
37    import static org.mockito.Mockito.*;
38   
39    /**
40    * Unit tests for {@link DocumentTableBlockDataSource}.
41    *
42    * @version $$Id$
43    * @since 5.0RC1
44    */
 
45    public class DocumentTableBlockDataSourceTest
46    {
47    @Rule
48    public MockitoComponentMockingRule<DocumentTableBlockDataSource> componentManager =
49    new MockitoComponentMockingRule<DocumentTableBlockDataSource>(DocumentTableBlockDataSource.class);
50   
 
51  1 toggle @Test
52    public void isDefinedChartSourceTheCurrentDocumentWhenReferenceNotNullAndMatching() throws Exception
53    {
54  1 DocumentAccessBridge dab = this.componentManager.getInstance(DocumentAccessBridge.class);
55  1 DocumentReference currentReference = new DocumentReference("currentwiki", "currentspace", "currentpage");
56  1 when(dab.getCurrentDocumentReference()).thenReturn(currentReference);
57   
58  1 DocumentReferenceResolver<String> resolver =
59    this.componentManager.getInstance(DocumentReferenceResolver.TYPE_STRING);
60  1 DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
61  1 when(resolver.resolve("wiki:space.page", currentReference)).thenReturn(documentReference);
62   
63  1 MacroBlock currentMacroBlock = mock(MacroBlock.class);
64  1 MetaDataBlock metaDataBlock = new MetaDataBlock(Collections.EMPTY_LIST,
65    new MetaData(Collections.singletonMap(MetaData.SOURCE, (Object) "wiki:space.page")));
66  1 when(currentMacroBlock.getFirstBlock(any(BlockMatcher.class), any(Block.Axes.class))).thenReturn(metaDataBlock);
67   
68  1 DocumentTableBlockDataSource source = this.componentManager.getComponentUnderTest();
69  1 source.setParameter("document", "wiki:space.page");
70   
71  1 Assert.assertTrue(source.isDefinedChartSourceTheCurrentDocument(currentMacroBlock));
72    }
73    }