View Javadoc

    1   package net.sourceforge.pmd.renderers;
    2
    3   import java.io.File;
    4   import java.io.IOException;
    5
    6   import net.sourceforge.pmd.PMD;
    7   import net.sourceforge.pmd.Report.ProcessingError;
    8
    9   import org.junit.After;
    10  import org.junit.Before;
    11
    12  public class YAHTMLRendererTest extends AbstractRendererTst {
    13
    14      private String outputDir;
    15
    16      @Before
    17      public void setUp() throws IOException {
    18          outputDir = getTemporaryDirectory("pmdtest").getAbsolutePath();
    19      }
    20
    21      @After
    22      public void cleanUp() {
    23          deleteDirectory(new File(outputDir));
    24      }
    25
    26      private File getTemporaryDirectory(String prefix) throws IOException {
    27          // TODO: move to util class?
    28          File dir = File.createTempFile(prefix, "");
    29          dir.delete();
    30          dir.mkdir();
    31          return dir;
    32      }
    33
    34      private void deleteDirectory(File dir) {
    35          // TODO: move to util class?
    36          File[] a = dir.listFiles();
    37          if (a != null) {
    38              for (File f: a) {
    39                  if (f.isDirectory()) {
    40                      deleteDirectory(f);
    41                  } else {
    42                      f.delete();
    43                  }
    44              }
    45          }
    46          dir.delete();
    47      }
    48
    49      @Override
    50      public Renderer getRenderer() {
    51  	Renderer result = new YAHTMLRenderer();
    52  	result.setProperty(YAHTMLRenderer.OUTPUT_DIR, outputDir);
    53          return result;
    54      }
    55
    56      @Override
    57      public String getExpected() {
    58          return "<h3 align=\"center\">The HTML files are located in '" + outputDir + "'.</h3>" + PMD.EOL;
    59      }
    60
    61      @Override
    62      public String getExpectedEmpty() {
    63          return getExpected();
    64      }
    65
    66      @Override
    67      public String getExpectedMultiple() {
    68          return getExpected();
    69      }
    70
    71      @Override
    72      public String getExpectedError(ProcessingError error) {
    73          return getExpected();
    74      }
    75
    76      public static junit.framework.Test suite() {
    77          return new junit.framework.JUnit4TestAdapter(YAHTMLRendererTest.class);
    78      }
    79  }