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 try {
38 task.execute();
39 throw new RuntimeException("Should have thrown a BuildException - no rulesets");
40 } catch (BuildException be) {
41
42 }
43 }
44
45 public void testNestedRuleset() {
46 PMDTask task = new PMDTask();
47 RuleSetWrapper r = new RuleSetWrapper();
48 r.addText("rulesets/basic.xml");
49 task.addRuleset(r);
50 r.addText("rulesets/design.xml");
51 task.addRuleset(r);
52 Formatter f = new Formatter();
53 task.addFormatter(f);
54
55
56 try {
57 task.execute();
58 } catch (BuildException be) {
59
60 }
61 }
62
63 public void testInvalidJDK() {
64 PMDTask task = new PMDTask();
65 task.setTargetJDK("1.6");
66 try {
67 task.execute();
68 throw new RuntimeException("Should have thrown a BuildException - JDK 1.6 targeted");
69 } catch (BuildException be) {
70
71 }
72 }
73 }
74