View Javadoc
1   ////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code for adherence to a set of rules.
3   // Copyright (C) 2001-2017 the original author or authors.
4   //
5   // This library is free software; you can redistribute it and/or
6   // modify it under the terms of the GNU Lesser General Public
7   // License as published by the Free Software Foundation; either
8   // version 2.1 of the License, or (at your option) any later version.
9   //
10  // This library 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 library; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  ////////////////////////////////////////////////////////////////////////////////
19  
20  package com.puppycrawl.tools.checkstyle.xpath;
21  
22  import static org.junit.Assert.assertEquals;
23  import static org.junit.Assert.fail;
24  
25  import org.junit.Before;
26  import org.junit.Test;
27  
28  import net.sf.saxon.om.AxisInfo;
29  
30  public class AttributeNodeTest {
31  
32      private static AttributeNode attributeNode;
33  
34      @Before
35      public void init() {
36          attributeNode = new AttributeNode("name", "value");
37      }
38  
39      @Test
40      public void testGetAttributeValue() {
41          try {
42              attributeNode.getAttributeValue("", "");
43              fail("Exception is excepted");
44          }
45          catch (UnsupportedOperationException ex) {
46              assertEquals(
47                  "Invalid exception message",
48                  "Operation is not supported",
49                  ex.getMessage());
50          }
51      }
52  
53      @Test
54      public void testGetParent() {
55          try {
56              attributeNode.getParent();
57              fail("Exception is excepted");
58          }
59          catch (UnsupportedOperationException ex) {
60              assertEquals(
61                  "Invalid exception message",
62                  "Operation is not supported",
63                  ex.getMessage());
64          }
65      }
66  
67      @Test
68      public void testGetRoot() {
69          try {
70              attributeNode.getRoot();
71              fail("Exception is excepted");
72          }
73          catch (UnsupportedOperationException ex) {
74              assertEquals(
75                  "Invalid exception message",
76                  "Operation is not supported",
77                  ex.getMessage());
78          }
79      }
80  
81      @Test
82      public void testGetStringValue() {
83          assertEquals("Invalid string value", "value", attributeNode.getStringValue());
84      }
85  
86      @Test
87      public void testIterate() {
88          try {
89              attributeNode.iterateAxis(AxisInfo.SELF);
90              fail("Exception is excepted");
91          }
92          catch (UnsupportedOperationException ex) {
93              assertEquals(
94                  "Invalid exception message",
95                  "Operation is not supported",
96                  ex.getMessage());
97          }
98      }
99  
100     @Test
101     public void testGetLineNumber() {
102         try {
103             attributeNode.getLineNumber();
104             fail("Exception is excepted");
105         }
106         catch (UnsupportedOperationException ex) {
107             assertEquals(
108                 "Invalid exception message",
109                 "Operation is not supported",
110                 ex.getMessage());
111         }
112     }
113 
114     @Test
115     public void testGetColumnNumber() {
116         try {
117             attributeNode.getColumnNumber();
118             fail("Exception is excepted");
119         }
120         catch (UnsupportedOperationException ex) {
121             assertEquals(
122                 "Invalid exception message",
123                 "Operation is not supported",
124                 ex.getMessage());
125         }
126     }
127 
128     @Test
129     public void testGetTokenType() {
130         try {
131             attributeNode.getTokenType();
132             fail("Exception is excepted");
133         }
134         catch (UnsupportedOperationException ex) {
135             assertEquals(
136                 "Invalid exception message",
137                 "Operation is not supported",
138                 ex.getMessage());
139         }
140     }
141 
142     @Test
143     public void testGetUnderlyingNode() {
144         try {
145             attributeNode.getUnderlyingNode();
146             fail("Exception is excepted");
147         }
148         catch (UnsupportedOperationException ex) {
149             assertEquals(
150                 "Invalid exception message",
151                 "Operation is not supported",
152                 ex.getMessage());
153         }
154     }
155 }