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;
21  
22  import static org.junit.Assert.assertEquals;
23  import static org.junit.Assert.assertTrue;
24  import static org.junit.Assert.fail;
25  import static org.powermock.api.mockito.PowerMockito.when;
26  
27  import java.io.File;
28  import java.io.FileInputStream;
29  import java.lang.reflect.Constructor;
30  import java.lang.reflect.Field;
31  import java.lang.reflect.InvocationTargetException;
32  import java.lang.reflect.Method;
33  import java.util.ArrayList;
34  import java.util.List;
35  import java.util.Properties;
36  
37  import org.junit.Test;
38  import org.junit.runner.RunWith;
39  import org.powermock.api.mockito.PowerMockito;
40  import org.powermock.core.classloader.annotations.PrepareForTest;
41  import org.powermock.modules.junit4.PowerMockRunner;
42  import org.powermock.reflect.Whitebox;
43  import org.xml.sax.Attributes;
44  import org.xml.sax.InputSource;
45  
46  import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
47  import com.puppycrawl.tools.checkstyle.api.Configuration;
48  
49  /**
50   * Unit test for ConfigurationLoader.
51   * @author Rick Giles
52   * @author lkuehne
53   */
54  @RunWith(PowerMockRunner.class)
55  @PrepareForTest({DefaultConfiguration.class, ConfigurationLoader.class})
56  public class ConfigurationLoaderTest extends AbstractPathTestSupport {
57  
58      @Override
59      protected String getPackageLocation() {
60          return "com/puppycrawl/tools/checkstyle/configurationloader";
61      }
62  
63      private Configuration loadConfiguration(String name) throws Exception {
64          return loadConfiguration(name, new Properties());
65      }
66  
67      private Configuration loadConfiguration(
68          String name, Properties props) throws Exception {
69          final String fName = getPath(name);
70  
71          return ConfigurationLoader.loadConfiguration(fName, new PropertiesExpander(props));
72      }
73  
74      private static Method getReplacePropertiesMethod() throws Exception {
75          final Class<?>[] params = new Class<?>[3];
76          params[0] = String.class;
77          params[1] = PropertyResolver.class;
78          params[2] = String.class;
79          final Class<ConfigurationLoader> configurationLoaderClass = ConfigurationLoader.class;
80          final Method replacePropertiesMethod =
81              configurationLoaderClass.getDeclaredMethod("replaceProperties", params);
82          replacePropertiesMethod.setAccessible(true);
83          return replacePropertiesMethod;
84      }
85  
86      @Test
87      public void testResourceLoadConfiguration() throws Exception {
88          final Properties props = new Properties();
89          props.setProperty("checkstyle.basedir", "basedir");
90  
91          // load config that's only found in the classpath
92          final DefaultConfiguration config =
93              (DefaultConfiguration) ConfigurationLoader.loadConfiguration(
94                  getPath("InputConfigurationLoaderChecks.xml"), new PropertiesExpander(props));
95  
96          //verify the root, and property substitution
97          final Properties attributes = new Properties();
98          attributes.setProperty("tabWidth", "4");
99          attributes.setProperty("basedir", "basedir");
100         verifyConfigNode(config, "Checker", 3, attributes);
101     }
102 
103     @Test
104     public void testResourceLoadConfigurationWithMultiThreadConfiguration() throws Exception {
105         final Properties props = new Properties();
106         props.setProperty("checkstyle.basedir", "basedir");
107 
108         final PropertiesExpander propertiesExpander = new PropertiesExpander(props);
109         final String configPath = getPath("InputConfigurationLoaderChecks.xml");
110         final ThreadModeSettings multiThreadModeSettings =
111             new ThreadModeSettings(4, 2);
112 
113         try {
114             ConfigurationLoader.loadConfiguration(
115                 configPath, propertiesExpander, multiThreadModeSettings);
116             fail("An exception is expected");
117         }
118         catch (IllegalArgumentException ex) {
119             assertEquals("Invalid exception message",
120                 "Multi thread mode for Checker module is not implemented",
121                 ex.getMessage());
122         }
123     }
124 
125     @Test
126     public void testResourceLoadConfigurationWithSingleThreadConfiguration() throws Exception {
127         final Properties props = new Properties();
128         props.setProperty("checkstyle.basedir", "basedir");
129 
130         final PropertiesExpander propertiesExpander = new PropertiesExpander(props);
131         final String configPath = getPath("InputConfigurationLoaderChecks.xml");
132         final ThreadModeSettings singleThreadModeSettings =
133             ThreadModeSettings.SINGLE_THREAD_MODE_INSTANCE;
134 
135         final DefaultConfiguration config =
136             (DefaultConfiguration) ConfigurationLoader.loadConfiguration(
137                 configPath, propertiesExpander, singleThreadModeSettings);
138 
139         final Properties attributes = new Properties();
140         attributes.setProperty("tabWidth", "4");
141         attributes.setProperty("basedir", "basedir");
142         verifyConfigNode(config, "Checker", 3, attributes);
143     }
144 
145     @Test
146     public void testEmptyConfiguration() throws Exception {
147         final DefaultConfiguration config =
148             (DefaultConfiguration) loadConfiguration("InputConfigurationLoaderEmpty.xml");
149         verifyConfigNode(config, "Checker", 0, new Properties());
150     }
151 
152     @Test
153     public void testEmptyModuleResolver() throws Exception {
154         final DefaultConfiguration config =
155             (DefaultConfiguration) loadConfiguration(
156                 "InputConfigurationLoaderEmpty.xml", new Properties());
157         verifyConfigNode(config, "Checker", 0, new Properties());
158     }
159 
160     @Test
161     public void testMissingPropertyName() throws Exception {
162         try {
163             loadConfiguration("InputConfigurationLoaderMissingPropertyName.xml");
164             fail("missing property name");
165         }
166         catch (CheckstyleException ex) {
167             assertTrue("Invalid exception message: " + ex.getMessage(),
168                     ex.getMessage().contains("\"name\""));
169             assertTrue("Invalid exception message: " + ex.getMessage(),
170                     ex.getMessage().contains("\"property\""));
171             assertTrue("Invalid exception message: " + ex.getMessage(),
172                     ex.getMessage().endsWith(":8:41"));
173         }
174     }
175 
176     @Test
177     public void testMissingPropertyNameInMethodWithBooleanParameter() throws Exception {
178         try {
179             final String fName = getPath("InputConfigurationLoaderMissingPropertyName.xml");
180             ConfigurationLoader.loadConfiguration(fName, new PropertiesExpander(new Properties()),
181                     false);
182 
183             fail("missing property name");
184         }
185         catch (CheckstyleException ex) {
186             assertTrue("Invalid exception message: " + ex.getMessage(),
187                     ex.getMessage().contains("\"name\""));
188             assertTrue("Invalid exception message: " + ex.getMessage(),
189                     ex.getMessage().contains("\"property\""));
190             assertTrue("Invalid exception message: " + ex.getMessage(),
191                     ex.getMessage().endsWith(":8:41"));
192         }
193     }
194 
195     @Test
196     public void testMissingPropertyValue() throws Exception {
197         try {
198             loadConfiguration("InputConfigurationLoaderMissingPropertyValue.xml");
199             fail("missing property value");
200         }
201         catch (CheckstyleException ex) {
202             assertTrue("Invalid exception message: " + ex.getMessage(),
203                     ex.getMessage().contains("\"value\""));
204             assertTrue("Invalid exception message: " + ex.getMessage(),
205                     ex.getMessage().contains("\"property\""));
206             assertTrue("Invalid exception message: " + ex.getMessage(),
207                     ex.getMessage().endsWith(":8:41"));
208         }
209     }
210 
211     @Test
212     public void testMissingConfigName() throws Exception {
213         try {
214             loadConfiguration("InputConfigurationLoaderMissingConfigName.xml");
215             fail("missing module name");
216         }
217         catch (CheckstyleException ex) {
218             assertTrue("Invalid exception message: " + ex.getMessage(),
219                     ex.getMessage().contains("\"name\""));
220             assertTrue("Invalid exception message: " + ex.getMessage(),
221                     ex.getMessage().contains("\"module\""));
222             assertTrue("Invalid exception message: " + ex.getMessage(),
223                     ex.getMessage().endsWith(":7:23"));
224         }
225     }
226 
227     @Test
228     public void testMissingConfigParent() throws Exception {
229         try {
230             loadConfiguration("InputConfigurationLoaderMissingConfigParent.xml");
231             fail("missing module parent");
232         }
233         catch (CheckstyleException ex) {
234             assertTrue("Invalid exception message: " + ex.getMessage(),
235                     ex.getMessage().contains("\"property\""));
236             assertTrue("Invalid exception message: " + ex.getMessage(),
237                     ex.getMessage().contains("\"module\""));
238             assertTrue("Invalid exception message: " + ex.getMessage(),
239                     ex.getMessage().endsWith(":8:38"));
240         }
241     }
242 
243     @Test
244     public void testCheckstyleChecks() throws Exception {
245         final Properties props = new Properties();
246         props.setProperty("checkstyle.basedir", "basedir");
247 
248         final DefaultConfiguration config =
249             (DefaultConfiguration) loadConfiguration(
250                 "InputConfigurationLoaderChecks.xml", props);
251 
252         //verify the root, and property substitution
253         final Properties atts = new Properties();
254         atts.setProperty("tabWidth", "4");
255         atts.setProperty("basedir", "basedir");
256         verifyConfigNode(config, "Checker", 3, atts);
257 
258         //verify children
259         final Configuration[] children = config.getChildren();
260         atts.clear();
261         verifyConfigNode(
262             (DefaultConfiguration) children[1], "JavadocPackage", 0, atts);
263         verifyConfigNode(
264             (DefaultConfiguration) children[2], "Translation", 0, atts);
265         atts.setProperty("testName", "testValue");
266         verifyConfigNode(
267             (DefaultConfiguration) children[0],
268             "TreeWalker",
269             8,
270             atts);
271 
272         //verify TreeWalker's first, last, NoWhitespaceAfterCheck
273         final Configuration[] grandchildren = children[0].getChildren();
274         atts.clear();
275         verifyConfigNode(
276             (DefaultConfiguration) grandchildren[0],
277             "AvoidStarImport",
278             0,
279             atts);
280         atts.setProperty("format", "System.out.println");
281         verifyConfigNode(
282             (DefaultConfiguration) grandchildren[grandchildren.length - 1],
283             "GenericIllegalRegexp",
284             0,
285             atts);
286         atts.clear();
287         atts.setProperty("tokens", "DOT");
288         atts.setProperty("allowLineBreaks", "true");
289         verifyConfigNode(
290             (DefaultConfiguration) grandchildren[6],
291             "NoWhitespaceAfter",
292             0,
293             atts);
294     }
295 
296     @Test
297     public void testCustomMessages() throws Exception {
298         final Properties props = new Properties();
299         props.setProperty("checkstyle.basedir", "basedir");
300 
301         final DefaultConfiguration config =
302             (DefaultConfiguration) loadConfiguration(
303                 "InputConfigurationLoaderCustomMessages.xml", props);
304 
305         final Configuration[] children = config.getChildren();
306         final Configuration[] grandchildren = children[0].getChildren();
307 
308         final String expectedKey = "name.invalidPattern";
309         assertTrue("Messages should contain key: " + expectedKey,
310             grandchildren[0].getMessages()
311             .containsKey(expectedKey));
312     }
313 
314     private static void verifyConfigNode(
315         DefaultConfiguration config, String name, int childrenLength,
316         Properties atts) throws Exception {
317         assertEquals("name.", name, config.getName());
318         assertEquals(
319             "children.length.",
320             childrenLength,
321             config.getChildren().length);
322 
323         final String[] attNames = config.getAttributeNames();
324         assertEquals("attributes.length", atts.size(), attNames.length);
325 
326         for (String attName : attNames) {
327             assertEquals(
328                 "attribute[" + attName + "]",
329                 atts.getProperty(attName),
330                 config.getAttribute(attName));
331         }
332     }
333 
334     @Test
335     public void testReplacePropertiesNoReplace() throws Exception {
336         final String[] testValues = {null, "", "a", "$a", "{a",
337                                      "{a}", "a}", "$a}", "$", "a$b", };
338         final Properties props = initProperties();
339         for (String testValue : testValues) {
340             final String value = (String) getReplacePropertiesMethod().invoke(
341                 null, testValue, new PropertiesExpander(props), null);
342             assertEquals("\"" + testValue + "\"", value, testValue);
343         }
344     }
345 
346     @Test
347     public void testReplacePropertiesSyntaxError() throws Exception {
348         final Properties props = initProperties();
349         try {
350             final String value = (String) getReplacePropertiesMethod().invoke(
351                 null, "${a", new PropertiesExpander(props), null);
352             fail("expected to fail, instead got: " + value);
353         }
354         catch (InvocationTargetException ex) {
355             assertEquals("Invalid exception cause message",
356                 "Syntax error in property: ${a", ex.getCause().getMessage());
357         }
358     }
359 
360     @Test
361     public void testReplacePropertiesMissingProperty() throws Exception {
362         final Properties props = initProperties();
363         try {
364             final String value = (String) getReplacePropertiesMethod().invoke(
365                 null, "${c}", new PropertiesExpander(props), null);
366             fail("expected to fail, instead got: " + value);
367         }
368         catch (InvocationTargetException ex) {
369             assertEquals("Invalid exception cause message",
370                 "Property ${c} has not been set", ex.getCause().getMessage());
371         }
372     }
373 
374     @Test
375     public void testReplacePropertiesReplace() throws Exception {
376         final String[][] testValues = {
377             {"${a}", "A"},
378             {"x${a}", "xA"},
379             {"${a}x", "Ax"},
380             {"${a}${b}", "AB"},
381             {"x${a}${b}", "xAB"},
382             {"${a}x${b}", "AxB"},
383             {"${a}${b}x", "ABx"},
384             {"x${a}y${b}", "xAyB"},
385             {"${a}x${b}y", "AxBy"},
386             {"x${a}${b}y", "xABy"},
387             {"x${a}y${b}z", "xAyBz"},
388             {"$$", "$"},
389         };
390         final Properties props = initProperties();
391         for (String[] testValue : testValues) {
392             final String value = (String) getReplacePropertiesMethod().invoke(
393                 null, testValue[0], new PropertiesExpander(props), null);
394             assertEquals("\"" + testValue[0] + "\"",
395                 testValue[1], value);
396         }
397     }
398 
399     private static Properties initProperties() {
400         final Properties props = new Properties();
401         props.setProperty("a", "A");
402         props.setProperty("b", "B");
403         return props;
404     }
405 
406     @Test
407     public void testExternalEntity() throws Exception {
408         final Properties props = new Properties();
409         props.setProperty("checkstyle.basedir", "basedir");
410 
411         final DefaultConfiguration config =
412             (DefaultConfiguration) loadConfiguration(
413                 "InputConfigurationLoaderExternalEntity.xml", props);
414 
415         final Properties atts = new Properties();
416         atts.setProperty("tabWidth", "4");
417         atts.setProperty("basedir", "basedir");
418         verifyConfigNode(config, "Checker", 2, atts);
419     }
420 
421     @Test
422     public void testExternalEntitySubdirectory() throws Exception {
423         final Properties props = new Properties();
424         props.setProperty("checkstyle.basedir", "basedir");
425 
426         final DefaultConfiguration config =
427             (DefaultConfiguration) loadConfiguration(
428                 "subdir/InputConfigurationLoaderExternalEntitySubDir.xml", props);
429 
430         final Properties attributes = new Properties();
431         attributes.setProperty("tabWidth", "4");
432         attributes.setProperty("basedir", "basedir");
433         verifyConfigNode(config, "Checker", 2, attributes);
434     }
435 
436     @Test
437     public void testExternalEntityFromUri() throws Exception {
438         final Properties props = new Properties();
439         props.setProperty("checkstyle.basedir", "basedir");
440 
441         final File file = new File(
442                 getPath("subdir/InputConfigurationLoaderExternalEntitySubDir.xml"));
443         final DefaultConfiguration config =
444             (DefaultConfiguration) ConfigurationLoader.loadConfiguration(
445                     file.toURI().toString(), new PropertiesExpander(props));
446 
447         final Properties atts = new Properties();
448         atts.setProperty("tabWidth", "4");
449         atts.setProperty("basedir", "basedir");
450         verifyConfigNode(config, "Checker", 2, atts);
451     }
452 
453     @Test
454     public void testIncorrectTag() throws Exception {
455         try {
456             final Class<?> aClassParent = ConfigurationLoader.class;
457             final Constructor<?> ctorParent = aClassParent.getDeclaredConstructor(
458                     PropertyResolver.class, boolean.class, ThreadModeSettings.class);
459             ctorParent.setAccessible(true);
460             final Object objParent = ctorParent.newInstance(null, true, null);
461 
462             final Class<?> aClass = Class.forName("com.puppycrawl.tools.checkstyle."
463                     + "ConfigurationLoader$InternalLoader");
464             final Constructor<?> constructor = aClass.getConstructor(objParent.getClass());
465             constructor.setAccessible(true);
466 
467             final Object obj = constructor.newInstance(objParent);
468 
469             final Class<?>[] param = new Class<?>[] {String.class, String.class,
470                 String.class, Attributes.class, };
471             final Method method = aClass.getDeclaredMethod("startElement", param);
472 
473             method.invoke(obj, "", "", "hello", null);
474 
475             fail("Exception is expected");
476 
477         }
478         catch (InvocationTargetException ex) {
479             assertTrue("Invalid exception cause",
480                 ex.getCause() instanceof IllegalStateException);
481             assertEquals("Invalid exception cause message",
482                 "Unknown name:" + "hello" + ".", ex.getCause().getMessage());
483         }
484     }
485 
486     @Test
487     public void testPrivateConstructorWithPropertyResolverAndOmitIgnoreModules() throws Exception {
488         final Class<?> configurationLoaderClass = ConfigurationLoader.class;
489         final Constructor<?> configurationLoaderCtor =
490                 configurationLoaderClass.getDeclaredConstructor(
491                         PropertyResolver.class, boolean.class);
492         configurationLoaderCtor.setAccessible(true);
493 
494         final Properties properties = new Properties();
495         final PropertyResolver propertyResolver = new PropertiesExpander(properties);
496         final ConfigurationLoader configurationLoader =
497                 (ConfigurationLoader) configurationLoaderCtor.newInstance(
498                         propertyResolver, true);
499 
500         final Field overridePropsResolverField =
501                 configurationLoaderClass.getDeclaredField("overridePropsResolver");
502         overridePropsResolverField.setAccessible(true);
503         assertEquals("Invalid property resolver",
504             propertyResolver, overridePropsResolverField.get(configurationLoader));
505 
506         final Field omitIgnoredModulesField =
507                 configurationLoaderClass.getDeclaredField("omitIgnoredModules");
508         omitIgnoredModulesField.setAccessible(true);
509         assertEquals("omitIgnoredModules should be set to true",
510             true, omitIgnoredModulesField.get(configurationLoader));
511     }
512 
513     @Test
514     public void testNonExistentPropertyName() throws Exception {
515         try {
516             loadConfiguration("InputConfigurationLoaderNonexistentProperty.xml");
517             fail("exception in expected");
518         }
519         catch (CheckstyleException ex) {
520             assertEquals("Invalid exception message",
521                 "unable to parse configuration stream", ex.getMessage());
522             assertEquals("Invalid exception cause message",
523                 "Property ${nonexistent} has not been set",
524                     ex.getCause().getMessage());
525         }
526     }
527 
528     @Test
529     public void testConfigWithIgnore() throws Exception {
530 
531         final DefaultConfiguration config =
532                 (DefaultConfiguration) ConfigurationLoader.loadConfiguration(
533                         getPath("InputConfigurationLoaderModuleIgnoreSeverity.xml"),
534                         new PropertiesExpander(new Properties()), true);
535 
536         final Configuration[] children = config.getChildren();
537         assertEquals("Invalid children count", 0, children[0].getChildren().length);
538     }
539 
540     @Test
541     public void testConfigWithIgnoreUsingInputSource() throws Exception {
542 
543         final DefaultConfiguration config =
544                 (DefaultConfiguration) ConfigurationLoader.loadConfiguration(new InputSource(
545                         new File(getPath("InputConfigurationLoaderModuleIgnoreSeverity.xml"))
546                             .toURI().toString()),
547                         new PropertiesExpander(new Properties()), true);
548 
549         final Configuration[] children = config.getChildren();
550         assertEquals("Invalid children count", 0, children[0].getChildren().length);
551     }
552 
553     @Test
554     public void testConfigCheckerWithIgnore() throws Exception {
555 
556         final DefaultConfiguration config =
557                 (DefaultConfiguration) ConfigurationLoader.loadConfiguration(
558                         getPath("InputConfigurationLoaderCheckerIgnoreSeverity.xml"),
559                         new PropertiesExpander(new Properties()), true);
560 
561         final Configuration[] children = config.getChildren();
562         assertEquals("Invalid children count", 0, children.length);
563     }
564 
565     @Test
566     public void testLoadConfigurationWrongUrl() {
567         try {
568             final DefaultConfiguration config =
569                     (DefaultConfiguration) ConfigurationLoader.loadConfiguration(
570                             ";InputConfigurationLoaderModuleIgnoreSeverity.xml",
571                             new PropertiesExpander(new Properties()), true);
572 
573             final Configuration[] children = config.getChildren();
574             assertEquals("Invalid children count", 0, children[0].getChildren().length);
575             fail("Exception is expected");
576         }
577         catch (CheckstyleException ex) {
578             assertEquals("Invalid exception message",
579                     "Unable to find: ;InputConfigurationLoaderModuleIgnoreSeverity.xml",
580                     ex.getMessage());
581         }
582     }
583 
584     @Test
585     public void testLoadConfigurationDeprecated() throws Exception {
586         final DefaultConfiguration config =
587                 (DefaultConfiguration) ConfigurationLoader.loadConfiguration(
588                         new FileInputStream(
589                             getPath("InputConfigurationLoaderModuleIgnoreSeverity.xml")),
590                         new PropertiesExpander(new Properties()), true);
591 
592         final Configuration[] children = config.getChildren();
593         assertEquals("Invalid children count",
594             0, children[0].getChildren().length);
595     }
596 
597     @Test
598     public void testReplacePropertiesDefault() throws Exception {
599         final Properties props = new Properties();
600         final String defaultValue = "defaultValue";
601 
602         final String value = (String) getReplacePropertiesMethod().invoke(
603             null, "${checkstyle.basedir}", new PropertiesExpander(props), defaultValue);
604 
605         assertEquals("Invalid property value", defaultValue, value);
606     }
607 
608     @Test
609     public void testLoadConfigurationFromClassPath() throws Exception {
610         final DefaultConfiguration config =
611                 (DefaultConfiguration) ConfigurationLoader.loadConfiguration(
612                         getPath("InputConfigurationLoaderModuleIgnoreSeverity.xml"),
613                         new PropertiesExpander(new Properties()), true);
614 
615         final Configuration[] children = config.getChildren();
616         assertEquals("Invalid children count",
617             0, children[0].getChildren().length);
618     }
619 
620     /**
621      * This SuppressWarning("unchecked") required to suppress
622      * "Unchecked generics array creation for varargs parameter" during mock.
623      * @throws Exception could happen from PowerMokito calls and getAttribute
624      */
625     @SuppressWarnings("unchecked")
626     @Test
627     public void testConfigWithIgnoreExceptionalAttributes() throws Exception {
628 
629         // emulate exception from unrelated code, but that is same try-catch
630         final DefaultConfiguration tested = PowerMockito.mock(DefaultConfiguration.class);
631         when(tested.getAttributeNames()).thenReturn(new String[] {"severity"});
632         when(tested.getName()).thenReturn("MemberName");
633         when(tested.getAttribute("severity")).thenThrow(CheckstyleException.class);
634         // to void creation of 2 other mocks for now reason, only one moc is used for all cases
635         PowerMockito.whenNew(DefaultConfiguration.class)
636                 .withArguments("MemberName", ThreadModeSettings.SINGLE_THREAD_MODE_INSTANCE)
637                 .thenReturn(tested);
638         PowerMockito.whenNew(DefaultConfiguration.class)
639                 .withArguments("Checker", ThreadModeSettings.SINGLE_THREAD_MODE_INSTANCE)
640                 .thenReturn(tested);
641         PowerMockito.whenNew(DefaultConfiguration.class)
642                 .withArguments("TreeWalker", ThreadModeSettings.SINGLE_THREAD_MODE_INSTANCE)
643                 .thenReturn(tested);
644 
645         try {
646             ConfigurationLoader.loadConfiguration(
647                     getPath("InputConfigurationLoaderModuleIgnoreSeverity.xml"),
648                     new PropertiesExpander(new Properties()), true);
649             fail("Exception is expected");
650         }
651         catch (CheckstyleException expected) {
652             assertEquals("Invalid exception cause message",
653                 "Problem during accessing 'severity' attribute for MemberName",
654                     expected.getCause().getMessage());
655         }
656     }
657 
658     @Test
659     public void testParsePropertyString() throws Exception {
660         final List<String> propertyRefs = new ArrayList<>();
661         final List<String> fragments = new ArrayList<>();
662 
663         Whitebox.invokeMethod(ConfigurationLoader.class,
664                 "parsePropertyString", "$",
665                fragments, propertyRefs);
666         assertEquals("Fragments list has unexpected amount of items",
667                 1, fragments.size());
668     }
669 
670     @Test
671     public void testConstructors() throws Exception {
672         final Properties props = new Properties();
673         props.setProperty("checkstyle.basedir", "basedir");
674         final String fName = getPath("InputConfigurationLoaderChecks.xml");
675 
676         final Configuration configuration = ConfigurationLoader.loadConfiguration(fName,
677                 new PropertiesExpander(props), ConfigurationLoader.IgnoredModulesOptions.OMIT);
678         assertEquals("Name is not expected", "Checker", configuration.getName());
679 
680         final DefaultConfiguration configuration1 =
681                 (DefaultConfiguration) ConfigurationLoader.loadConfiguration(
682                         new InputSource(new FileInputStream(
683                             getPath("InputConfigurationLoaderModuleIgnoreSeverity.xml"))),
684                         new PropertiesExpander(new Properties()),
685                         ConfigurationLoader.IgnoredModulesOptions.EXECUTE);
686 
687         final Configuration[] children = configuration1.getChildren();
688         assertEquals("Unexpected children size", 1, children[0].getChildren().length);
689     }
690 }