KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cobertura > reporting > xml > XMLReportTest


1 /*
2  * Cobertura - http://cobertura.sourceforge.net/
3  *
4  * Copyright (C) 2005 Mark Doliner
5  *
6  * Cobertura is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published
8  * by the Free Software Foundation; either version 2 of the License,
9  * or (at your option) any later version.
10  *
11  * Cobertura is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Cobertura; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  */

21
22 package net.sourceforge.cobertura.reporting.xml;
23
24 import java.io.File JavaDoc;
25
26 import junit.framework.TestCase;
27 import net.sourceforge.cobertura.coveragedata.ClassData;
28 import net.sourceforge.cobertura.coveragedata.ProjectData;
29 import net.sourceforge.cobertura.reporting.ComplexityCalculator;
30 import net.sourceforge.cobertura.reporting.JUnitXMLHelper;
31 import net.sourceforge.cobertura.util.FileFinder;
32
33 public class XMLReportTest extends TestCase
34 {
35
36     private final static String JavaDoc BASEDIR = (System.getProperty("basedir") != null) ? System
37             .getProperty("basedir") : ".";
38     private final static String JavaDoc PATH_TO_TEST_OUTPUT = BASEDIR + "/build/test/XMLReportTest";
39     private File JavaDoc tmpDir;
40
41     public void setUp()
42     {
43         tmpDir = new File JavaDoc(PATH_TO_TEST_OUTPUT);
44         tmpDir.mkdirs();
45     }
46
47     public void tearDown()
48     {
49         tmpDir = new File JavaDoc(PATH_TO_TEST_OUTPUT);
50         File JavaDoc files[] = tmpDir.listFiles();
51         for (int i = 0; i < files.length; i++)
52             files[i].delete();
53         tmpDir.delete();
54     }
55
56     public void testXMLReportWithNonSourceLines() throws Exception JavaDoc
57     {
58         ProjectData projectData = new ProjectData();
59
60         // Adding line to the project data that hasn't been yet marked as source line
61
ClassData cd = projectData.getOrCreateClassData(XMLReport.class.getName());
62         cd.touch(7777);
63
64         File JavaDoc reportDir = File.createTempFile("XMLReportTest", "");
65         reportDir.delete();
66         reportDir.mkdir();
67
68         FileFinder fileFinder = new FileFinder();
69         ComplexityCalculator complexity = new ComplexityCalculator(fileFinder);
70
71         new XMLReport(projectData, reportDir, fileFinder, complexity);
72
73         File JavaDoc coverageFile = new File JavaDoc(reportDir, "coverage.xml");
74         JUnitXMLHelper.readXmlFile(coverageFile, true);
75
76         coverageFile.delete();
77         reportDir.delete();
78     }
79
80 }
81
Popular Tags