| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.rendering.block.match; |
| 21 |
|
|
| 22 |
|
import java.util.Arrays; |
| 23 |
|
|
| 24 |
|
import org.junit.Assert; |
| 25 |
|
import org.junit.Test; |
| 26 |
|
import org.xwiki.rendering.block.Block; |
| 27 |
|
import org.xwiki.rendering.block.ParagraphBlock; |
| 28 |
|
import org.xwiki.rendering.block.WordBlock; |
| 29 |
|
|
| |
|
| 75.4% |
Uncovered Elements: 14 (57) |
Complexity: 9 |
Complexity Density: 0.19 |
|
| 30 |
|
public class BlockNavigatorTest |
| 31 |
|
{ |
| 32 |
|
public static final WordBlock precedingBlockChild1 = new WordBlock("pc1"); |
| 33 |
|
|
| 34 |
|
public static final WordBlock precedingBlockChild2 = new WordBlock("pc2"); |
| 35 |
|
|
| 36 |
|
public static final ParagraphBlock precedingBlock = new ParagraphBlock(Arrays.<Block>asList(precedingBlockChild1, |
| 37 |
|
precedingBlockChild2)) |
| 38 |
|
{ |
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 39 |
0 |
@Override... |
| 40 |
|
public String toString() |
| 41 |
|
{ |
| 42 |
0 |
return "precedingBlock"; |
| 43 |
|
} |
| 44 |
|
}; |
| 45 |
|
|
| 46 |
|
public static final WordBlock contextBlockChild21 = new WordBlock("cc21"); |
| 47 |
|
|
| 48 |
|
public static final WordBlock contextBlockChild22 = new WordBlock("cc22"); |
| 49 |
|
|
| 50 |
|
public static final ParagraphBlock contextBlockChild2 = new ParagraphBlock(Arrays.<Block>asList( |
| 51 |
|
contextBlockChild21, contextBlockChild22)) |
| 52 |
|
{ |
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 53 |
0 |
@Override... |
| 54 |
|
public String toString() |
| 55 |
|
{ |
| 56 |
0 |
return "contextBlockChild2"; |
| 57 |
|
} |
| 58 |
|
}; |
| 59 |
|
|
| 60 |
|
public static final WordBlock contextBlockChild11 = new WordBlock("cc11"); |
| 61 |
|
|
| 62 |
|
public static final WordBlock contextBlockChild12 = new WordBlock("cc12"); |
| 63 |
|
|
| 64 |
|
public static final ParagraphBlock contextBlockChild1 = new ParagraphBlock(Arrays.<Block>asList( |
| 65 |
|
contextBlockChild11, contextBlockChild12)) |
| 66 |
|
{ |
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 67 |
0 |
@Override... |
| 68 |
|
public String toString() |
| 69 |
|
{ |
| 70 |
0 |
return "contextBlockChild1"; |
| 71 |
|
} |
| 72 |
|
}; |
| 73 |
|
|
| 74 |
|
public static final ParagraphBlock contextBlock = new ParagraphBlock(Arrays.<Block>asList(contextBlockChild1, |
| 75 |
|
contextBlockChild2)) |
| 76 |
|
{ |
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 77 |
0 |
@Override... |
| 78 |
|
public String toString() |
| 79 |
|
{ |
| 80 |
0 |
return "contextBlock"; |
| 81 |
|
} |
| 82 |
|
}; |
| 83 |
|
|
| 84 |
|
public static final WordBlock followingBlockChild1 = new WordBlock("fc1"); |
| 85 |
|
|
| 86 |
|
public static final WordBlock followingBlockChild2 = new WordBlock("fc2"); |
| 87 |
|
|
| 88 |
|
public static final ParagraphBlock followingBlock = new ParagraphBlock(Arrays.<Block>asList(followingBlockChild1, |
| 89 |
|
followingBlockChild2)) |
| 90 |
|
{ |
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 91 |
0 |
@Override... |
| 92 |
|
public String toString() |
| 93 |
|
{ |
| 94 |
0 |
return "followingBlock"; |
| 95 |
|
} |
| 96 |
|
}; |
| 97 |
|
|
| 98 |
|
public static final ParagraphBlock parentBlock = new ParagraphBlock(Arrays.<Block>asList(precedingBlock, |
| 99 |
|
contextBlock, followingBlock)) |
| 100 |
|
{ |
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 101 |
0 |
@Override... |
| 102 |
|
public String toString() |
| 103 |
|
{ |
| 104 |
0 |
return "parentBlock"; |
| 105 |
|
} |
| 106 |
|
}; |
| 107 |
|
|
| 108 |
|
public static final ParagraphBlock rootBlock = new ParagraphBlock(Arrays.<Block>asList(parentBlock)) |
| 109 |
|
{ |
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 110 |
0 |
@Override... |
| 111 |
|
public String toString() |
| 112 |
|
{ |
| 113 |
0 |
return "rootBlock"; |
| 114 |
|
} |
| 115 |
|
}; |
| 116 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
| 117 |
1 |
@Test... |
| 118 |
|
public void testGetBlocks() |
| 119 |
|
{ |
| 120 |
1 |
BlockNavigator navigator = new BlockNavigator(); |
| 121 |
|
|
| 122 |
1 |
Assert.assertEquals(Arrays.asList(parentBlock, rootBlock), |
| 123 |
|
navigator.getBlocks(contextBlock, Block.Axes.ANCESTOR)); |
| 124 |
1 |
Assert.assertEquals(Arrays.asList(contextBlock, parentBlock, rootBlock), |
| 125 |
|
navigator.getBlocks(contextBlock, Block.Axes.ANCESTOR_OR_SELF)); |
| 126 |
1 |
Assert.assertEquals(Arrays.asList(contextBlockChild1, contextBlockChild2), |
| 127 |
|
navigator.getBlocks(contextBlock, Block.Axes.CHILD)); |
| 128 |
1 |
Assert.assertEquals(Arrays.asList(contextBlockChild1, contextBlockChild11, contextBlockChild12, |
| 129 |
|
contextBlockChild2, contextBlockChild21, contextBlockChild22), navigator.getBlocks(contextBlock, |
| 130 |
|
Block.Axes.DESCENDANT)); |
| 131 |
1 |
Assert.assertEquals(Arrays.asList(contextBlock, contextBlockChild1, contextBlockChild11, contextBlockChild12, |
| 132 |
|
contextBlockChild2, contextBlockChild21, contextBlockChild22), navigator.getBlocks(contextBlock, |
| 133 |
|
Block.Axes.DESCENDANT_OR_SELF)); |
| 134 |
1 |
Assert.assertEquals(Arrays.asList(followingBlock, followingBlockChild1, followingBlockChild2), |
| 135 |
|
navigator.getBlocks(contextBlock, Block.Axes.FOLLOWING)); |
| 136 |
1 |
Assert.assertEquals(Arrays.asList(followingBlock), |
| 137 |
|
navigator.getBlocks(contextBlock, Block.Axes.FOLLOWING_SIBLING)); |
| 138 |
1 |
Assert.assertEquals(Arrays.asList(parentBlock), navigator.getBlocks(contextBlock, Block.Axes.PARENT)); |
| 139 |
1 |
Assert.assertEquals(Arrays.asList(precedingBlock, precedingBlockChild1, precedingBlockChild2), |
| 140 |
|
navigator.getBlocks(contextBlock, Block.Axes.PRECEDING)); |
| 141 |
1 |
Assert.assertEquals(Arrays.asList(precedingBlock), |
| 142 |
|
navigator.getBlocks(contextBlock, Block.Axes.PRECEDING_SIBLING)); |
| 143 |
1 |
Assert.assertEquals(Arrays.asList(contextBlock), navigator.getBlocks(contextBlock, Block.Axes.SELF)); |
| 144 |
|
} |
| 145 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (29) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
| 146 |
1 |
@Test... |
| 147 |
|
public void testGetFirstBlock() |
| 148 |
|
{ |
| 149 |
1 |
BlockNavigator navigator = new BlockNavigator(); |
| 150 |
|
|
| 151 |
1 |
Assert.assertSame(parentBlock, navigator.getFirstBlock(contextBlock, Block.Axes.ANCESTOR)); |
| 152 |
1 |
Assert.assertSame(contextBlock, navigator.getFirstBlock(contextBlock, Block.Axes.ANCESTOR_OR_SELF)); |
| 153 |
1 |
Assert.assertSame(contextBlockChild1, navigator.getFirstBlock(contextBlock, Block.Axes.CHILD)); |
| 154 |
1 |
Assert.assertSame(contextBlockChild1, navigator.getFirstBlock(contextBlock, Block.Axes.DESCENDANT)); |
| 155 |
1 |
Assert.assertSame(contextBlock, navigator.getFirstBlock(contextBlock, Block.Axes.DESCENDANT_OR_SELF)); |
| 156 |
1 |
Assert.assertSame(followingBlock, navigator.getFirstBlock(contextBlock, Block.Axes.FOLLOWING)); |
| 157 |
|
|
| 158 |
1 |
Assert.assertSame(followingBlock, navigator.getFirstBlock(contextBlock, Block.Axes.FOLLOWING_SIBLING)); |
| 159 |
|
|
| 160 |
1 |
Assert.assertSame(parentBlock, navigator.getFirstBlock(contextBlock, Block.Axes.PARENT)); |
| 161 |
1 |
Assert.assertSame(precedingBlock, navigator.getFirstBlock(contextBlock, Block.Axes.PRECEDING)); |
| 162 |
|
|
| 163 |
1 |
Assert.assertSame(precedingBlock, navigator.getFirstBlock(contextBlock, Block.Axes.PRECEDING_SIBLING)); |
| 164 |
|
|
| 165 |
1 |
Assert.assertSame(contextBlock, navigator.getFirstBlock(contextBlock, Block.Axes.SELF)); |
| 166 |
|
|
| 167 |
|
|
| 168 |
|
|
| 169 |
1 |
navigator = new BlockNavigator(new SameBlockMatcher(rootBlock)); |
| 170 |
|
|
| 171 |
1 |
Assert.assertSame(rootBlock, navigator.getFirstBlock(contextBlock, Block.Axes.ANCESTOR_OR_SELF)); |
| 172 |
1 |
Assert.assertSame(rootBlock, navigator.getFirstBlock(contextBlock, Block.Axes.ANCESTOR)); |
| 173 |
|
|
| 174 |
1 |
navigator = new BlockNavigator(new SameBlockMatcher(contextBlockChild22)); |
| 175 |
|
|
| 176 |
1 |
Assert.assertSame(contextBlockChild22, navigator.getFirstBlock(contextBlock, Block.Axes.DESCENDANT)); |
| 177 |
|
|
| 178 |
1 |
Assert.assertSame(contextBlockChild22, navigator.getFirstBlock(contextBlock, Block.Axes.DESCENDANT_OR_SELF)); |
| 179 |
|
|
| 180 |
1 |
navigator = new BlockNavigator(new SameBlockMatcher(followingBlockChild2)); |
| 181 |
|
|
| 182 |
1 |
Assert.assertSame(followingBlockChild2, navigator.getFirstBlock(contextBlock, Block.Axes.FOLLOWING)); |
| 183 |
|
|
| 184 |
1 |
navigator = new BlockNavigator(new SameBlockMatcher(contextBlockChild2)); |
| 185 |
|
|
| 186 |
1 |
Assert.assertSame(contextBlockChild2, navigator.getFirstBlock(contextBlock, Block.Axes.CHILD)); |
| 187 |
|
|
| 188 |
1 |
navigator = new BlockNavigator(new SameBlockMatcher(precedingBlockChild2)); |
| 189 |
|
|
| 190 |
1 |
Assert.assertSame(precedingBlockChild2, navigator.getFirstBlock(contextBlock, Block.Axes.PRECEDING)); |
| 191 |
|
|
| 192 |
1 |
navigator = new BlockNavigator(new SameBlockMatcher(new WordBlock("unexistingBlock"))); |
| 193 |
|
|
| 194 |
1 |
Assert.assertNull(navigator.getFirstBlock(contextBlock, Block.Axes.PRECEDING_SIBLING)); |
| 195 |
1 |
Assert.assertNull(navigator.getFirstBlock(contextBlock, Block.Axes.PARENT)); |
| 196 |
1 |
Assert.assertNull(navigator.getFirstBlock(contextBlock, Block.Axes.FOLLOWING_SIBLING)); |
| 197 |
1 |
Assert.assertNull(navigator.getFirstBlock(contextBlock, Block.Axes.SELF)); |
| 198 |
|
} |
| 199 |
|
} |