net.sourceforge.pmd.testframework

## Class RuleTst

- java.lang.Object
- - net.sourceforge.pmd.testframework.RuleTst

- Direct Known Subclasses:
    AbstractRendererTst, CyclomaticComplexityTest, DocumentNavigatorTest, ExcludeLinesTest, NPathComplexityTest, ReportTest, RuleSetTest, SimpleAggregatorTst, SuppressWarningsTest, XMLRendererTest, XPathJspRuleTest, XPathRuleTest

      public abstract class RuleTst
      extends Object

  Advanced methods for test cases

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static Language` | `DEFAULT_LANGUAGE`
    `static LanguageVersion` | `DEFAULT_LANGUAGE_VERSION`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RuleTst()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `TestDescriptor[]` | `extractTestsFromXml(Rule rule)` Extract a set of tests from an XML file.
    `TestDescriptor[]` | `extractTestsFromXml(Rule rule, String testsFileName)`
    `TestDescriptor[]` | `extractTestsFromXml(Rule rule, String testsFileName, String baseDirectory)` Extract a set of tests from an XML file with the given name.
    `Rule` | `findRule(String ruleSet, String ruleName)` Find a rule in a certain ruleset by name
    `protected String` | `getCleanRuleName(Rule rule)` getResourceAsStream tries to find the XML file in weird locations if the ruleName includes the package, so we strip it here.
    `void` | `runTest(TestDescriptor test)` Run the rule on the given code, and check the expected number of violations.
    `void` | `runTestFromString(String code, Rule rule, Report report)` Run the test using the DEFAULT_LANGUAGE_VERSION and put the violations in the report.
    `void` | `runTestFromString(String code, Rule rule, Report report, LanguageVersion languageVersion)` Run the rule on the given code and put the violations in the report.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_LANGUAGE_VERSION

          public static final LanguageVersion DEFAULT_LANGUAGE_VERSION

    - #### DEFAULT_LANGUAGE

          public static final Language DEFAULT_LANGUAGE

  - ### Constructor Detail

    - #### RuleTst

          public RuleTst()

  - ### Method Detail

    - #### findRule

          public Rule findRule(String ruleSet,
                      String ruleName)

      Find a rule in a certain ruleset by name

    - #### runTest

          public void runTest(TestDescriptor test)

      Run the rule on the given code, and check the expected number of violations.

    - #### runTestFromString

          public void runTestFromString(String code,
                               Rule rule,
                               Report report,
                               LanguageVersion languageVersion)
                                 throws PMDException

      Run the rule on the given code and put the violations in the report.
      Throws:
        `PMDException`

    - #### getCleanRuleName

          protected String getCleanRuleName(Rule rule)

      getResourceAsStream tries to find the XML file in weird locations if the ruleName includes the package, so we strip it here.

    - #### extractTestsFromXml

          public TestDescriptor[] extractTestsFromXml(Rule rule)

      Extract a set of tests from an XML file. The file should be ./xml/RuleName.xml relative to the test class. The format is defined in test-data.xsd.

    - #### extractTestsFromXml

          public TestDescriptor[] extractTestsFromXml(Rule rule,
                                             String testsFileName)

    - #### extractTestsFromXml

          public TestDescriptor[] extractTestsFromXml(Rule rule,
                                             String testsFileName,
                                             String baseDirectory)

      Extract a set of tests from an XML file with the given name. The file should be ./xml/[testsFileName].xml relative to the test class. The format is defined in test-data.xsd.

    - #### runTestFromString

          public void runTestFromString(String code,
                               Rule rule,
                               Report report)
                                 throws PMDException

      Run the test using the DEFAULT_LANGUAGE_VERSION and put the violations in the report. Convenience method.
      Throws:
        `PMDException`

Copyright © 2002-2013 InfoEther. All Rights Reserved.