1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.puppycrawl.tools.checkstyle.xpath.iterators;
21
22 import static com.google.common.truth.Truth.assertWithMessage;
23 import static com.puppycrawl.tools.checkstyle.internal.utils.XpathIteratorUtil.findNode;
24
25 import org.junit.jupiter.api.Test;
26
27 import net.sf.saxon.om.NodeInfo;
28
29 public class FollowingIteratorTest {
30
31 @Test
32 public void testFollowingSibling() {
33 final NodeInfo startNode = findNode("ANNOTATIONS");
34
35 try (FollowingIterator iterator = new FollowingIterator(startNode)) {
36 assertWithMessage("Invalid node")
37 .that(iterator.next())
38 .isEqualTo(findNode("CLASS_DEF"));
39 assertWithMessage("Invalid node")
40 .that(iterator.next())
41 .isEqualTo(findNode("OBJBLOCK"));
42 assertWithMessage("Invalid node")
43 .that(iterator.next())
44 .isEqualTo(findNode("LCURLY"));
45 assertWithMessage("Invalid node")
46 .that(iterator.next())
47 .isEqualTo(findNode("METHOD_DEF"));
48 assertWithMessage("Invalid node")
49 .that(iterator.next())
50 .isEqualTo(findNode("RCURLY"));
51 assertWithMessage("Invalid node")
52 .that(iterator.next())
53 .isEqualTo(findNode("PARAMETERS"));
54 assertWithMessage("Invalid node")
55 .that(iterator.next())
56 .isEqualTo(findNode("SLIST"));
57 assertWithMessage("Node should be null")
58 .that(iterator.next())
59 .isNull();
60 assertWithMessage("Node should be null")
61 .that(iterator.next())
62 .isNull();
63 }
64 }
65
66 @Test
67 public void testNoSibling() {
68 final NodeInfo startNode = findNode("CLASS_DEF");
69
70 try (FollowingIterator iterator = new FollowingIterator(startNode)) {
71 assertWithMessage("Node should be null")
72 .that(iterator.next())
73 .isNull();
74 }
75 }
76 }