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
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.List;
27
28 import org.junit.jupiter.api.Test;
29
30 import com.puppycrawl.tools.checkstyle.api.DetailAST;
31 import com.puppycrawl.tools.checkstyle.xpath.AbstractNode;
32 import net.sf.saxon.om.NamespaceUri;
33 import net.sf.saxon.om.NodeInfo;
34
35 public class ReverseListIteratorTest {
36
37 @Test
38 public void testCorrectOrder() {
39 final List<AbstractNode> nodes = Arrays.asList(new TestNode(), new TestNode(),
40 new TestNode());
41
42 try (ReverseListIterator iterator = new ReverseListIterator(nodes)) {
43 for (int i = nodes.size() - 1; i >= 0; i--) {
44 assertWithMessage("Invalid node")
45 .that(iterator.next())
46 .isEqualTo(nodes.get(i));
47 }
48 assertWithMessage("Node should be null")
49 .that(iterator.next())
50 .isNull();
51 }
52 }
53
54 @Test
55 public void testNullList() {
56 try (ReverseListIterator iterator = new ReverseListIterator(null)) {
57 assertWithMessage("Node should be null")
58 .that(iterator.next())
59 .isNull();
60 }
61 }
62
63 private static final class TestNode extends AbstractNode {
64
65 private TestNode() {
66 super(null);
67 }
68
69 @Override
70 public int getTokenType() {
71 return 0;
72 }
73
74 @Override
75 public DetailAST getUnderlyingNode() {
76 return null;
77 }
78
79 @Override
80 public int getDepth() {
81 return 0;
82 }
83
84 @Override
85 protected List<AbstractNode> createChildren() {
86 return new ArrayList<>();
87 }
88
89 @Override
90 public int getNodeKind() {
91 return 0;
92 }
93
94 @Override
95 public int compareOrder(NodeInfo other) {
96 return 0;
97 }
98
99 @Override
100 public String getLocalPart() {
101 return null;
102 }
103
104 @Override
105 public NodeInfo getParent() {
106 return null;
107 }
108
109 @Override
110 public String getAttributeValue(NamespaceUri uri, String local) {
111 return null;
112 }
113
114 @Override
115 public NodeInfo getRoot() {
116 return null;
117 }
118
119 @Override
120 public boolean hasChildNodes() {
121 return false;
122 }
123 }
124 }