1 package com.puppycrawl.tools.checkstyle.checks.coding; 2 3 import com.puppycrawl.tools.checkstyle.BaseCheckTestCase; 4 import com.puppycrawl.tools.checkstyle.DefaultConfiguration; 5 6 public class HiddenFieldCheckTest 7 extends BaseCheckTestCase 8 { 9 public void testNoParameters() 10 throws Exception 11 { 12 final DefaultConfiguration checkConfig = 13 createCheckConfig(HiddenFieldCheck.class); 14 checkConfig.addAttribute("tokens", "VARIABLE_DEF"); 15 final String [] expected = { 16 "18:13: 'hidden' hides a field.", 17 "27:13: 'hidden' hides a field.", 18 "32:18: 'hidden' hides a field.", 19 "46:17: 'innerHidden' hides a field.", 20 "55:17: 'innerHidden' hides a field.", 21 "56:17: 'hidden' hides a field.", 22 "61:22: 'innerHidden' hides a field.", 23 "64:22: 'hidden' hides a field.", 24 "76:17: 'innerHidden' hides a field.", 25 "77:17: 'hidden' hides a field.", 26 "82:13: 'hidden' hides a field.", 27 "138:13: 'hidden' hides a field.", 28 "143:13: 'hidden' hides a field.", 29 "148:13: 'hidden' hides a field.", 30 "152:13: 'hidden' hides a field.", 31 "200:17: 'hidden' hides a field.", 32 "217:13: 'hidden' hides a field.", 33 "223:13: 'hiddenStatic' hides a field.", 34 }; 35 verify(checkConfig, getPath("InputHiddenField.java"), expected); 36 } 37 38 public void testDefault() 39 throws Exception 40 { 41 final DefaultConfiguration checkConfig = 42 createCheckConfig(HiddenFieldCheck.class); 43 final String [] expected = { 44 "18:13: 'hidden' hides a field.", 45 "21:33: 'hidden' hides a field.", 46 "27:13: 'hidden' hides a field.", 47 "32:18: 'hidden' hides a field.", 48 "36:33: 'hidden' hides a field.", 49 "46:17: 'innerHidden' hides a field.", 50 "49:26: 'innerHidden' hides a field.", 51 "55:17: 'innerHidden' hides a field.", 52 "56:17: 'hidden' hides a field.", 53 "61:22: 'innerHidden' hides a field.", 54 "64:22: 'hidden' hides a field.", 55 "69:17: 'innerHidden' hides a field.", 56 "70:17: 'hidden' hides a field.", 57 "76:17: 'innerHidden' hides a field.", 58 "77:17: 'hidden' hides a field.", 59 "82:13: 'hidden' hides a field.", 60 "100:29: 'prop' hides a field.", 61 "106:29: 'prop' hides a field.", 62 "112:29: 'prop' hides a field.", 63 "124:28: 'prop' hides a field.", 64 "138:13: 'hidden' hides a field.", 65 "143:13: 'hidden' hides a field.", 66 "148:13: 'hidden' hides a field.", 67 "152:13: 'hidden' hides a field.", 68 "179:23: 'y' hides a field.", 69 "200:17: 'hidden' hides a field.", 70 "210:20: 'hidden' hides a field.", 71 "217:13: 'hidden' hides a field.", 72 "223:13: 'hiddenStatic' hides a field.", 73 "230:41: 'x' hides a field.", 74 }; 75 verify(checkConfig, getPath("InputHiddenField.java"), expected); 76 } 77 78 79 public void testIgnoreFormat() 80 throws Exception 81 { 82 final DefaultConfiguration checkConfig = 83 createCheckConfig(HiddenFieldCheck.class); 84 checkConfig.addAttribute("ignoreFormat", "^i.*$"); 85 final String [] expected = { 86 "18:13: 'hidden' hides a field.", 87 "21:33: 'hidden' hides a field.", 88 "27:13: 'hidden' hides a field.", 89 "32:18: 'hidden' hides a field.", 90 "36:33: 'hidden' hides a field.", 91 "56:17: 'hidden' hides a field.", 92 "64:22: 'hidden' hides a field.", 93 "70:17: 'hidden' hides a field.", 94 "77:17: 'hidden' hides a field.", 95 "82:13: 'hidden' hides a field.", 96 "100:29: 'prop' hides a field.", 97 "106:29: 'prop' hides a field.", 98 "112:29: 'prop' hides a field.", 99 "124:28: 'prop' hides a field.", 100 "138:13: 'hidden' hides a field.", 101 "143:13: 'hidden' hides a field.", 102 "148:13: 'hidden' hides a field.", 103 "152:13: 'hidden' hides a field.", 104 "179:23: 'y' hides a field.", 105 "200:17: 'hidden' hides a field.", 106 "210:20: 'hidden' hides a field.", 107 "217:13: 'hidden' hides a field.", 108 "223:13: 'hiddenStatic' hides a field.", 109 "230:41: 'x' hides a field.", 110 }; 111 verify(checkConfig, getPath("InputHiddenField.java"), expected); 112 } 113 114 115 public void testIgnoreSetter() 116 throws Exception 117 { 118 final DefaultConfiguration checkConfig = 119 createCheckConfig(HiddenFieldCheck.class); 120 checkConfig.addAttribute("ignoreSetter", "true"); 121 final String [] expected = { 122 "18:13: 'hidden' hides a field.", 123 "21:33: 'hidden' hides a field.", 124 "27:13: 'hidden' hides a field.", 125 "32:18: 'hidden' hides a field.", 126 "36:33: 'hidden' hides a field.", 127 "46:17: 'innerHidden' hides a field.", 128 "49:26: 'innerHidden' hides a field.", 129 "55:17: 'innerHidden' hides a field.", 130 "56:17: 'hidden' hides a field.", 131 "61:22: 'innerHidden' hides a field.", 132 "64:22: 'hidden' hides a field.", 133 "69:17: 'innerHidden' hides a field.", 134 "70:17: 'hidden' hides a field.", 135 "76:17: 'innerHidden' hides a field.", 136 "77:17: 'hidden' hides a field.", 137 "82:13: 'hidden' hides a field.", 138 "106:29: 'prop' hides a field.", 139 "112:29: 'prop' hides a field.", 140 "124:28: 'prop' hides a field.", 141 "138:13: 'hidden' hides a field.", 142 "143:13: 'hidden' hides a field.", 143 "148:13: 'hidden' hides a field.", 144 "152:13: 'hidden' hides a field.", 145 "179:23: 'y' hides a field.", 146 "200:17: 'hidden' hides a field.", 147 "210:20: 'hidden' hides a field.", 148 "217:13: 'hidden' hides a field.", 149 "223:13: 'hiddenStatic' hides a field.", 150 "230:41: 'x' hides a field.", 151 }; 152 verify(checkConfig, getPath("InputHiddenField.java"), expected); 153 } 154 155 156 public void testIgnoreConstructorParameter() 157 throws Exception 158 { 159 final DefaultConfiguration checkConfig = 160 createCheckConfig(HiddenFieldCheck.class); 161 checkConfig.addAttribute("ignoreConstructorParameter", "true"); 162 final String [] expected = { 163 "18:13: 'hidden' hides a field.", 164 "27:13: 'hidden' hides a field.", 165 "32:18: 'hidden' hides a field.", 166 "36:33: 'hidden' hides a field.", 167 "46:17: 'innerHidden' hides a field.", 168 "55:17: 'innerHidden' hides a field.", 169 "56:17: 'hidden' hides a field.", 170 "61:22: 'innerHidden' hides a field.", 171 "64:22: 'hidden' hides a field.", 172 "69:17: 'innerHidden' hides a field.", 173 "70:17: 'hidden' hides a field.", 174 "76:17: 'innerHidden' hides a field.", 175 "77:17: 'hidden' hides a field.", 176 "82:13: 'hidden' hides a field.", 177 "100:29: 'prop' hides a field.", 178 "106:29: 'prop' hides a field.", 179 "112:29: 'prop' hides a field.", 180 "124:28: 'prop' hides a field.", 181 "138:13: 'hidden' hides a field.", 182 "143:13: 'hidden' hides a field.", 183 "148:13: 'hidden' hides a field.", 184 "152:13: 'hidden' hides a field.", 185 "179:23: 'y' hides a field.", 186 "200:17: 'hidden' hides a field.", 187 "217:13: 'hidden' hides a field.", 188 "223:13: 'hiddenStatic' hides a field.", 189 "230:41: 'x' hides a field.", 190 }; 191 verify(checkConfig, getPath("InputHiddenField.java"), expected); 192 } 193 194 195 public void testReordered() 196 throws Exception 197 { 198 final DefaultConfiguration checkConfig = 199 createCheckConfig(HiddenFieldCheck.class); 200 final String [] expected = { 201 "18:13: 'hidden' hides a field.", 202 "21:40: 'hidden' hides a field.", 203 "27:13: 'hidden' hides a field.", 204 "32:18: 'hidden' hides a field.", 205 "36:33: 'hidden' hides a field.", 206 "46:17: 'innerHidden' hides a field.", 207 "49:26: 'innerHidden' hides a field.", 208 "55:17: 'innerHidden' hides a field.", 209 "56:17: 'hidden' hides a field.", 210 "61:22: 'innerHidden' hides a field.", 211 "64:22: 'hidden' hides a field.", 212 "69:17: 'innerHidden' hides a field.", 213 "70:17: 'hidden' hides a field.", 214 "76:17: 'innerHidden' hides a field.", 215 "77:17: 'hidden' hides a field.", 216 "83:13: 'hidden' hides a field.", 217 "105:17: 'hidden' hides a field.", 218 "118:21: 'hidden' hides a field.", 219 "125:13: 'hidden' hides a field.", 220 "131:13: 'hiddenStatic' hides a field.", 221 }; 222 verify(checkConfig, getPath("InputHiddenFieldReorder.java"), expected); 223 } 224 225 public void testIgnoreAbstractMethods() throws Exception 226 { 227 final DefaultConfiguration checkConfig = 228 createCheckConfig(HiddenFieldCheck.class); 229 checkConfig.addAttribute("ignoreAbstractMethods", "true"); 230 231 final String [] expected = { 232 "18:13: 'hidden' hides a field.", 233 "21:33: 'hidden' hides a field.", 234 "27:13: 'hidden' hides a field.", 235 "32:18: 'hidden' hides a field.", 236 "36:33: 'hidden' hides a field.", 237 "46:17: 'innerHidden' hides a field.", 238 "49:26: 'innerHidden' hides a field.", 239 "55:17: 'innerHidden' hides a field.", 240 "56:17: 'hidden' hides a field.", 241 "61:22: 'innerHidden' hides a field.", 242 "64:22: 'hidden' hides a field.", 243 "69:17: 'innerHidden' hides a field.", 244 "70:17: 'hidden' hides a field.", 245 "76:17: 'innerHidden' hides a field.", 246 "77:17: 'hidden' hides a field.", 247 "82:13: 'hidden' hides a field.", 248 "100:29: 'prop' hides a field.", 249 "106:29: 'prop' hides a field.", 250 "112:29: 'prop' hides a field.", 251 "124:28: 'prop' hides a field.", 252 "138:13: 'hidden' hides a field.", 253 "143:13: 'hidden' hides a field.", 254 "148:13: 'hidden' hides a field.", 255 "152:13: 'hidden' hides a field.", 256 "179:23: 'y' hides a field.", 257 "200:17: 'hidden' hides a field.", 258 "210:20: 'hidden' hides a field.", 259 "217:13: 'hidden' hides a field.", 260 "223:13: 'hiddenStatic' hides a field.", 261 }; 262 verify(checkConfig, getPath("InputHiddenField.java"), expected); 263 } 264 } 265 | Popular Tags |