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.ArrayList;
7   import java.util.List;
8   import java.util.Properties;
9   
10  import net.sourceforge.pmd.Rule;
11  import net.sourceforge.pmd.lang.LanguageVersion;
12  
13  import org.junit.Ignore;
14  
15  /**
16   * Stores the information required to run a complete test.
17   */
18  @Ignore("this is not a unit test")
19  public class TestDescriptor {
20      private Rule rule;
21      private Properties properties;
22      private String description;
23      private int numberOfProblemsExpected;
24      private List<String> expectedMessages = new ArrayList<String>();
25      private List<Integer> expectedLineNumbers = new ArrayList<Integer>();
26      private String code;
27      private LanguageVersion languageVersion;
28      private boolean reinitializeRule = true;   //default, avoids unintentional mixing of state between test cases
29      private boolean isRegressionTest = true;
30  
31      // Empty descriptor added to please mvn surefire plugin
32      public TestDescriptor() {
33      	
34      }
35      
36      public TestDescriptor(String code, String description, int numberOfProblemsExpected, Rule rule) {
37          this(code, description, numberOfProblemsExpected, rule, RuleTst.DEFAULT_LANGUAGE_VERSION);
38      }
39      
40      public TestDescriptor(String code, String description, int numberOfProblemsExpected, Rule rule, LanguageVersion languageVersion) {
41          this.rule = rule;
42          this.code = code;
43          this.description = description;
44          this.numberOfProblemsExpected = numberOfProblemsExpected;
45          this.languageVersion = languageVersion;
46      }
47  
48      public void setExpectedMessages(List<String> messages) {
49          expectedMessages.clear();
50          expectedMessages.addAll(messages);
51      }
52  
53      public List<String> getExpectedMessages() {
54          return expectedMessages;
55      }
56  
57      public void setExpectedLineNumbers(List<Integer> expectedLineNumbers) {
58          this.expectedLineNumbers.clear();
59          this.expectedLineNumbers.addAll(expectedLineNumbers);
60      }
61  
62      public List<Integer> getExpectedLineNumbers() {
63          return expectedLineNumbers;
64      }
65  
66      public void setProperties(Properties properties) {
67          this.properties = properties;
68      }
69      
70      public Properties getProperties() {
71          return properties;
72      }
73      
74      public String getCode() {
75          return code;
76      }
77  
78      public LanguageVersion getLanguageVersion() {
79          return languageVersion;
80      }
81  
82      public String getDescription() {
83          return description;
84      }
85  
86      public int getNumberOfProblemsExpected() {
87          return numberOfProblemsExpected;
88      }
89  
90      public Rule getRule() {
91          return rule;
92      }
93  
94      public boolean getReinitializeRule() {
95          return reinitializeRule;
96      }
97  
98      public void setReinitializeRule(boolean reinitializeRule) {
99          this.reinitializeRule = reinitializeRule;
100     }
101 
102     /**
103      * Checks whether we are testing for regression problems only.
104      * Return value is based on the system property "pmd.regress".
105      * 
106      * @return <code>false</code> if system property "pmd.regress" is set to <code>false</code>, <code>true</code> otherwise
107      */
108     public static boolean inRegressionTestMode() {
109 	boolean inRegressionMode = true; // default
110 	try {
111 	    //get the "pmd.regress" System property
112 	    String property = System.getProperty("pmd.regress");
113 	    if (property != null) {
114 		inRegressionMode = Boolean.parseBoolean(property);
115 	    }
116 	} catch (IllegalArgumentException e) {
117 	} catch (NullPointerException e) {
118 	}
119 	
120         return inRegressionMode;
121     }
122 
123     public boolean isRegressionTest() {
124         return isRegressionTest;
125     }
126 
127     public void setRegressionTest(boolean isRegressionTest) {
128         this.isRegressionTest = isRegressionTest;
129     }
130 }