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 net.sourceforge.pmd.ant.Formatter;
7   import net.sourceforge.pmd.ant.PMDTask;
8   import net.sourceforge.pmd.ant.RuleSetWrapper;
9   
10  import org.apache.tools.ant.BuildException;
11  import org.junit.Ignore;
12  import org.junit.Test;
13  
14  public class PMDTaskTest {
15  
16      @Test(expected = BuildException.class)
17      public void testNoFormattersValidation() {
18          PMDTask task = new PMDTask();
19          task.execute();
20      }
21  
22      @Test(expected = BuildException.class)
23      public void testFormatterWithNoToFileAttribute() {
24          PMDTask task = new PMDTask();
25          task.addFormatter(new Formatter());
26          task.execute();
27      }
28  
29      @Test(expected = BuildException.class)
30      public void testNoRuleSets() {
31          PMDTask task = new PMDTask();
32          task.execute();
33      }
34  
35      @Ignore("This test has a TODO in it")
36      @Test
37      public void testNestedRuleset() {
38          PMDTask task = new PMDTask();
39          RuleSetWrapper r = new RuleSetWrapper();
40          r.addText("rulesets/basic.xml");
41          task.addRuleset(r);
42          r.addText("rulesets/design.xml");
43          task.addRuleset(r);
44          Formatter f = new Formatter();
45          task.addFormatter(f);
46          
47          //TODO
48          try {
49              task.execute();
50          } catch (BuildException be) {
51              //fail(be.toString());
52          }
53      }
54  
55      @Test(expected = BuildException.class)
56      public void testInvalidJDK() {
57          PMDTask task = new PMDTask();
58          task.setTargetJDK("1.7");
59          task.execute();
60      }
61  
62      public static junit.framework.Test suite() {
63          return new junit.framework.JUnit4TestAdapter(PMDTaskTest.class);
64      }
65  }