View Javadoc

1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.ant;
5   
6   import static org.junit.Assert.assertFalse;
7   import static org.junit.Assert.assertTrue;
8   import static org.junit.Assert.fail;
9   
10  import java.io.File;
11  
12  import net.sourceforge.pmd.renderers.CSVRenderer;
13  import net.sourceforge.pmd.renderers.HTMLRenderer;
14  import net.sourceforge.pmd.renderers.TextRenderer;
15  import net.sourceforge.pmd.renderers.XMLRenderer;
16  
17  import org.junit.Test;
18  
19  public class FormatterTest {
20  
21      @Test
22      public void testType() {
23          Formatter f = new Formatter();
24          f.setType("xml");
25          assertTrue(f.createRenderer() instanceof XMLRenderer);
26          f.setType("text");
27          assertTrue(f.createRenderer() instanceof TextRenderer);
28          f.setType("csv");
29          assertTrue(f.createRenderer() instanceof CSVRenderer);
30          f.setType("html");
31          assertTrue(f.createRenderer() instanceof HTMLRenderer);
32          try {
33              f.setType("FAIL");
34              f.createRenderer();
35              fail("Expected IllegalArgumentException");
36          } catch (IllegalArgumentException be) {
37              assertTrue(be.getMessage().startsWith("Can't find the custom format FAIL"));
38          }
39      }
40  
41      @Test
42      public void testNull() {
43          Formatter f = new Formatter();
44          assertTrue("Formatter toFile should start off null!", f.isNoOutputSupplied());
45          f.setToFile(new File("foo"));
46          assertFalse("Formatter toFile should not be null!", f.isNoOutputSupplied());
47      }
48  }