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

File EmptyBlockChainingListenerTest.java

 

Code metrics

0
16
7
1
99
57
7
0.44
2.29
7
1

Classes

Class Line # Actions
EmptyBlockChainingListenerTest 35 16 0% 7 0
1.0100%
 

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.listener.chaining;
21   
22    import java.util.Collections;
23    import java.util.Map;
24   
25    import org.junit.Assert;
26    import org.junit.Before;
27    import org.junit.Test;
28   
29    /**
30    * Unit tests for {@link LookaheadChainingListener}.
31    *
32    * @version $Id: a51fbd61639d57b8024d8dc664fb7b83a4f533d1 $
33    * @since 2.0M3
34    */
 
35    public class EmptyBlockChainingListenerTest
36    {
37    private ListenerChain chain;
38   
39    private EmptyBlockChainingListener listener;
40   
 
41  2 toggle @Before
42    public void setUp()
43    {
44  2 this.chain = new ListenerChain();
45  2 this.listener = new EmptyBlockChainingListener(this.chain);
46  2 this.chain.addListener(this.listener);
47    }
48   
49    /**
50    * Verify that isCurrentContainerBlockEmpty return true if there's no children inside a paragraph container block.
51    */
 
52  1 toggle @Test
53    public void testEmptyParagraphContainer()
54    {
55  1 this.chain.addListener(new AbstractChainingListener()
56    {
 
57  1 toggle {
58  1 setListenerChain(EmptyBlockChainingListenerTest.this.chain);
59    }
60   
 
61  1 toggle @Override
62    public void endParagraph(Map<String, String> parameters)
63    {
64  1 EmptyBlockChainingListener blockState =
65    (EmptyBlockChainingListener) getListenerChain().getListener(EmptyBlockChainingListener.class);
66  1 Assert.assertTrue(blockState.isCurrentContainerBlockEmpty());
67    }
68    });
69   
70  1 this.listener.beginParagraph(Collections.<String, String>emptyMap());
71  1 this.listener.endParagraph(Collections.<String, String>emptyMap());
72    }
73   
74    /**
75    * Verify that isCurrentContainerBlockEmpty return false if there are children inside a paragraph container block.
76    */
 
77  1 toggle @Test
78    public void testNonEmptyParagraphContainer()
79    {
80  1 this.chain.addListener(new AbstractChainingListener()
81    {
 
82  1 toggle {
83  1 setListenerChain(EmptyBlockChainingListenerTest.this.chain);
84    }
85   
 
86  1 toggle @Override
87    public void endParagraph(Map<String, String> parameters)
88    {
89  1 EmptyBlockChainingListener blockState =
90    (EmptyBlockChainingListener) getListenerChain().getListener(EmptyBlockChainingListener.class);
91  1 Assert.assertFalse(blockState.isCurrentContainerBlockEmpty());
92    }
93    });
94   
95  1 this.listener.beginParagraph(Collections.<String, String>emptyMap());
96  1 this.listener.onWord("word");
97  1 this.listener.endParagraph(Collections.<String, String>emptyMap());
98    }
99    }