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