1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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.Test; |
27 |
|
import org.xwiki.rendering.listener.MetaData; |
28 |
|
|
29 |
|
|
30 |
|
@link |
31 |
|
|
32 |
|
@version |
33 |
|
@since |
34 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 1 |
Complexity Density: 0.04 |
|
35 |
|
public class LookaheadChainingListenerTest |
36 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 5 |
Complexity Density: 1 |
|
37 |
|
public class TestChainingListener extends AbstractChainingListener |
38 |
|
{ |
39 |
|
public int calls = 0; |
40 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
41 |
1 |
public TestChainingListener(ListenerChain listenerChain)... |
42 |
|
{ |
43 |
1 |
setListenerChain(listenerChain); |
44 |
|
} |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
46 |
1 |
@Override... |
47 |
|
public void beginDocument(MetaData metadata) |
48 |
|
{ |
49 |
1 |
this.calls++; |
50 |
|
} |
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
52 |
2 |
@Override... |
53 |
|
public void beginParagraph(Map<String, String> parameters) |
54 |
|
{ |
55 |
2 |
this.calls++; |
56 |
|
} |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
58 |
1 |
@Override... |
59 |
|
public void endDocument(MetaData metadata) |
60 |
|
{ |
61 |
1 |
this.calls++; |
62 |
|
} |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
1 |
@Override... |
65 |
|
public void endParagraph(Map<String, String> parameters) |
66 |
|
{ |
67 |
1 |
this.calls++; |
68 |
|
} |
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
71 |
1 |
@Test... |
72 |
|
public void testLookahead() |
73 |
|
{ |
74 |
1 |
ListenerChain chain = new ListenerChain(); |
75 |
1 |
LookaheadChainingListener listener = new LookaheadChainingListener(chain, 2); |
76 |
1 |
chain.addListener(listener); |
77 |
1 |
TestChainingListener testListener = new TestChainingListener(chain); |
78 |
1 |
chain.addListener(testListener); |
79 |
|
|
80 |
|
|
81 |
1 |
listener.beginDocument(MetaData.EMPTY); |
82 |
1 |
Assert.assertEquals(1, testListener.calls); |
83 |
|
|
84 |
|
|
85 |
1 |
listener.beginParagraph(Collections.<String, String>emptyMap()); |
86 |
1 |
Assert.assertEquals(1, testListener.calls); |
87 |
1 |
Assert.assertEquals(EventType.BEGIN_PARAGRAPH, listener.getNextEvent().eventType); |
88 |
1 |
Assert.assertNull(listener.getNextEvent(2)); |
89 |
|
|
90 |
|
|
91 |
1 |
listener.beginParagraph(Collections.<String, String>emptyMap()); |
92 |
1 |
Assert.assertEquals(1, testListener.calls); |
93 |
1 |
Assert.assertEquals(EventType.BEGIN_PARAGRAPH, listener.getNextEvent().eventType); |
94 |
1 |
Assert.assertEquals(EventType.BEGIN_PARAGRAPH, listener.getNextEvent(2).eventType); |
95 |
1 |
Assert.assertNull(listener.getNextEvent(3)); |
96 |
|
|
97 |
|
|
98 |
1 |
listener.endParagraph(Collections.<String, String>emptyMap()); |
99 |
1 |
Assert.assertEquals(2, testListener.calls); |
100 |
1 |
Assert.assertEquals(EventType.BEGIN_PARAGRAPH, listener.getNextEvent().eventType); |
101 |
1 |
Assert.assertEquals(EventType.END_PARAGRAPH, listener.getNextEvent(2).eventType); |
102 |
1 |
Assert.assertNull(listener.getNextEvent(3)); |
103 |
|
|
104 |
|
|
105 |
1 |
listener.endDocument(MetaData.EMPTY); |
106 |
1 |
Assert.assertEquals(5, testListener.calls); |
107 |
1 |
Assert.assertNull(listener.getNextEvent()); |
108 |
|
} |
109 |
|
} |