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

File MacroBlockDumperTest.java

 
testIllegalArgumentException: Unsupported block [org.xwiki.rendering.block.WordBlock].
 

Code metrics

0
67
6
1
175
119
6
0.09
11.17
6
1

Classes

Class Line # Actions
MacroBlockDumperTest 48 67 0% 6 4
0.9452054594.5%
 

Contributing tests

This file is covered by 5 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.signature.internal;
21   
22    import java.util.Collections;
23    import java.util.HashMap;
24    import java.util.Map;
25   
26    import org.junit.Before;
27    import org.junit.Rule;
28    import org.junit.Test;
29    import org.junit.rules.ExpectedException;
30    import org.xwiki.rendering.block.Block;
31    import org.xwiki.rendering.block.MacroBlock;
32    import org.xwiki.rendering.block.MacroMarkerBlock;
33    import org.xwiki.rendering.block.WordBlock;
34    import org.xwiki.rendering.block.XDOM;
35    import org.xwiki.rendering.listener.MetaData;
36    import org.xwiki.test.mockito.MockitoComponentMockingRule;
37   
38    import static org.hamcrest.CoreMatchers.not;
39    import static org.hamcrest.core.IsEqual.equalTo;
40    import static org.junit.Assert.assertThat;
41   
42    /**
43    * Unit test for {@link org.xwiki.rendering.signature.internal.MacroBlockDumper}.
44    *
45    * @version $Id: 31a8f16804ef965564ebf603c786ceddd5a54bf7 $
46    * @since 6.1M2
47    */
 
48    public class MacroBlockDumperTest
49    {
50    @Rule
51    public final MockitoComponentMockingRule<BlockDumper> mocker =
52    new MockitoComponentMockingRule<BlockDumper>(MacroBlockDumper.class);
53   
54    @Rule
55    public ExpectedException thrown = ExpectedException.none();
56   
57    private Map<String, String> params = new HashMap<>();
58   
59    private BlockDumper dumper;
60   
 
61  5 toggle @Before
62    public void setUp() throws Exception
63    {
64  5 dumper = mocker.getComponentUnderTest();
65    }
66   
 
67  1 toggle @Test
68    public void testDumpMacroBlockWithoutSource() throws Exception
69    {
70  1 byte[] dump1 = dumper.dump(new MacroBlock("macro", params, "content", false));
71  1 byte[] dump2 = dumper.dump(new MacroBlock("macro", params, "content", false));
72  1 assertThat(dump1, equalTo(dump2));
73   
74  1 dump2 = dumper.dump(new MacroBlock("macro", params, "content", true));
75  1 assertThat(dump1, equalTo(dump2));
76   
77  1 dump2 = dumper.dump(new MacroBlock("macro2", params, "content", false));
78  1 assertThat(dump1, not(equalTo(dump2)));
79   
80  1 dump2 = dumper.dump(new MacroBlock("macro", params, false));
81  1 assertThat(dump1, not(equalTo(dump2)));
82   
83  1 dump2 = dumper.dump(new MacroBlock("macro", params, "content2", false));
84  1 assertThat(dump1, not(equalTo(dump2)));
85   
86  1 params.put("param", "value");
87  1 dump2 = dumper.dump(new MacroBlock("macro", params, "content", false));
88  1 assertThat(dump1, not(equalTo(dump2)));
89   
90  1 dump1 = dumper.dump(new MacroBlock("macro", params, "content", false));
91  1 assertThat(dump1, equalTo(dump2));
92   
93  1 params.put("param", "value2");
94  1 dump2 = dumper.dump(new MacroBlock("macro", params, "content", false));
95  1 assertThat(dump1, not(equalTo(dump2)));
96   
97  1 params.clear();
98  1 params.put("param2", "value");
99  1 dump2 = dumper.dump(new MacroBlock("macro", params, "content", false));
100  1 assertThat(dump1, not(equalTo(dump2)));
101   
102  1 params.clear();
103  1 params.put("param", "value");
104  1 params.put("param2", "value2");
105  1 dump2 = dumper.dump(new MacroBlock("macro", params, "content", false));
106  1 assertThat(dump1, not(equalTo(dump2)));
107    }
108   
 
109  1 toggle @Test
110    public void testDumpMacroBlockWithSource() throws Exception
111    {
112  1 Block macro1 = new MacroBlock("macro", params, "content", false);
113  1 Block macro2 = new MacroBlock("macro", params, "content", false);
114  1 XDOM xdom1 = new XDOM(Collections.singletonList(macro1));
115  1 XDOM xdom2 = new XDOM(Collections.singletonList(macro2));
116  1 xdom1.getMetaData().addMetaData(MetaData.SOURCE, "source");
117  1 xdom2.getMetaData().addMetaData(MetaData.SOURCE, "source");
118   
119  1 byte[] dump1 = dumper.dump(macro1);
120  1 byte[] dump2 = dumper.dump(macro2);
121  1 assertThat(dump1, equalTo(dump2));
122   
123  1 dump2 = dumper.dump(new MacroBlock("macro", params, "content", false));
124  1 assertThat(dump1, not(equalTo(dump2)));
125   
126  1 xdom2.getMetaData().addMetaData(MetaData.SOURCE, "other");
127  1 dump2 = dumper.dump(macro2);
128  1 assertThat(dump1, not(equalTo(dump2)));
129   
130  1 xdom2.getMetaData().addMetaData(MetaData.SOURCE, null);
131  1 dump1 = dumper.dump(new MacroBlock("macro", params, "content", false));
132  1 dump2 = dumper.dump(macro2);
133  1 assertThat(dump1, equalTo(dump2));
134    }
135   
 
136  1 toggle @Test
137    public void testDumpMacroMarkerBlockWithoutSource() throws Exception
138    {
139  1 byte[] dump1 = dumper.dump(new MacroBlock("macro", params, "content", false));
140  1 byte[] dump2 = dumper.dump(new MacroMarkerBlock("macro", params, "content", Collections.<Block>emptyList(), false));
141  1 assertThat(dump1, equalTo(dump2));
142   
143  1 params.put("param", "value");
144  1 params.put("param2", "value2");
145  1 dump1 = dumper.dump(new MacroBlock("macro", params, "content", false));
146  1 dump2 = dumper.dump(new MacroMarkerBlock("macro", params, "content", Collections.<Block>emptyList(), false));
147  1 assertThat(dump1, equalTo(dump2));
148    }
149   
 
150  1 toggle @Test
151    public void testDumpMacroMarkerBlockWithSource() throws Exception
152    {
153  1 Block macro1 = new MacroBlock("macro", params, "content", false);
154  1 Block macro2 = new MacroMarkerBlock("macro", params, "content", Collections.<Block>emptyList(), false);
155  1 XDOM xdom1 = new XDOM(Collections.singletonList(macro1));
156  1 XDOM xdom2 = new XDOM(Collections.singletonList(macro2));
157  1 xdom1.getMetaData().addMetaData(MetaData.SOURCE, "source");
158  1 xdom2.getMetaData().addMetaData(MetaData.SOURCE, "source");
159   
160  1 byte[] dump1 = dumper.dump(macro1);
161  1 byte[] dump2 = dumper.dump(macro2);
162  1 assertThat(dump1, equalTo(dump2));
163    }
164   
 
165  0 toggle @Test
166    public void testIllegalArgumentException() throws Exception
167    {
168  0 thrown.expect(IllegalArgumentException.class);
169  0 thrown.expectMessage("Unsupported block [org.xwiki.rendering.block.WordBlock].");
170   
171  0 Test failure here dumper.dump(new WordBlock("macro"));
172    }
173    }
174   
175