1 /***
2 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3 */
4 package test.net.sourceforge.pmd.ant;
5
6 import junit.framework.TestCase;
7 import net.sourceforge.pmd.ant.Formatter;
8 import net.sourceforge.pmd.ant.PMDTask;
9 import net.sourceforge.pmd.ant.RuleSetWrapper;
10 import org.apache.tools.ant.BuildException;
11
12 public class PMDTaskTest extends TestCase {
13
14 public void testNoFormattersValidation() {
15 PMDTask task = new PMDTask();
16 try {
17 task.execute();
18 throw new RuntimeException("Should have thrown a BuildException - no Formatters");
19 } catch (BuildException be) {
20
21 }
22 }
23
24 public void testFormatterWithNoToFileAttribute() {
25 PMDTask task = new PMDTask();
26 task.addFormatter(new Formatter());
27 try {
28 task.execute();
29 throw new RuntimeException("Should have thrown a BuildException - a Formatter was missing a toFile attribute");
30 } catch (BuildException be) {
31
32 }
33 }
34
35 public void testNoRuleSets() {
36 PMDTask task = new PMDTask();
37 task.setPrintToConsole(true);
38 try {
39 task.execute();
40 throw new RuntimeException("Should have thrown a BuildException - no rulesets");
41 } catch (BuildException be) {
42
43 }
44 }
45
46 public void testNestedRuleset() {
47 PMDTask task = new PMDTask();
48 RuleSetWrapper r = new RuleSetWrapper();
49 r.addText("rulesets/basic.xml");
50 task.addRuleset(r);
51 r.addText("rulesets/design.xml");
52 task.addRuleset(r);
53 Formatter f = new Formatter();
54 task.addFormatter(f);
55
56
57 try {
58 task.execute();
59 } catch (BuildException be) {
60
61 }
62 }
63
64 public void testInValidJDK() {
65 PMDTask task = new PMDTask();
66 task.setTargetJDK("1.6");
67 try {
68 task.execute();
69 throw new RuntimeException("Should have thrown a BuildException - JDK 1.6 targeted");
70 } catch (BuildException be) {
71
72 }
73 }
74 }
75