View Javadoc

    1   /**
    2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
    3    */
    4   package net.sourceforge.pmd.testframework;
    5
    6   import java.util.Properties;
    7
    8   import net.sourceforge.pmd.Rule;
    9   import net.sourceforge.pmd.lang.LanguageVersion;
    10
    11  import org.junit.Ignore;
    12
    13  /**
    14   * Stores the information required to run a complete test.
    15   */
    16  @Ignore("this is not a unit test")
    17  public class TestDescriptor {
    18      private Rule rule;
    19      private Properties properties;
    20      private String description;
    21      private int numberOfProblemsExpected;
    22      private String code;
    23      private LanguageVersion languageVersion;
    24      private boolean reinitializeRule = true;   //default, avoids unintentional mixing of state between test cases
    25      private boolean isRegressionTest = true;
    26
    27      // Empty descriptor added to please mvn surefire plugin
    28      public TestDescriptor() {
    29
    30      }
    31
    32      public TestDescriptor(String code, String description, int numberOfProblemsExpected, Rule rule) {
    33          this(code, description, numberOfProblemsExpected, rule, RuleTst.DEFAULT_LANGUAGE_VERSION);
    34      }
    35
    36      public TestDescriptor(String code, String description, int numberOfProblemsExpected, Rule rule, LanguageVersion languageVersion) {
    37          this.rule = rule;
    38          this.code = code;
    39          this.description = description;
    40          this.numberOfProblemsExpected = numberOfProblemsExpected;
    41          this.languageVersion = languageVersion;
    42      }
    43
    44      public void setProperties(Properties properties) {
    45          this.properties = properties;
    46      }
    47
    48      public Properties getProperties() {
    49          return properties;
    50      }
    51
    52      public String getCode() {
    53          return code;
    54      }
    55
    56      public LanguageVersion getLanguageVersion() {
    57          return languageVersion;
    58      }
    59
    60      public String getDescription() {
    61          return description;
    62      }
    63
    64      public int getNumberOfProblemsExpected() {
    65          return numberOfProblemsExpected;
    66      }
    67
    68      public Rule getRule() {
    69          return rule;
    70      }
    71
    72      public boolean getReinitializeRule() {
    73          return reinitializeRule;
    74      }
    75
    76      public void setReinitializeRule(boolean reinitializeRule) {
    77          this.reinitializeRule = reinitializeRule;
    78      }
    79
    80      /**
    81       * Checks whether we are testing for regression problems only.
    82       * Return value is based on the system property "pmd.regress".
    83       *
    84       * @return <code>false</code> if system property "pmd.regress" is set to <code>false</code>, <code>true</code> otherwise
    85       */
    86      public static boolean inRegressionTestMode() {
    87  	boolean inRegressionMode = true; // default
    88  	try {
    89  	    //get the "pmd.regress" System property
    90  	    String property = System.getProperty("pmd.regress");
    91  	    if (property != null) {
    92  		inRegressionMode = Boolean.parseBoolean(property);
    93  	    }
    94  	} catch (IllegalArgumentException e) {
    95  	} catch (NullPointerException e) {
    96  	}
    97
    98          return inRegressionMode;
    99      }
    100
    101     public boolean isRegressionTest() {
    102         return isRegressionTest;
    103     }
    104
    105     public void setRegressionTest(boolean isRegressionTest) {
    106         this.isRegressionTest = isRegressionTest;
    107     }
    108 }