KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cobertura > coveragedata > CoverageDataFileHandlerTest


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.coveragedata;
23
24 import java.io.File JavaDoc;
25
26 import junit.framework.TestCase;
27
28 public class CoverageDataFileHandlerTest extends TestCase
29 {
30
31     private final static String JavaDoc basedir = (System.getProperty("basedir") != null)
32             ? System.getProperty("basedir")
33             : ".";
34     private final static String JavaDoc pathToTestOutput = basedir
35             + "/build/test/CoverageDataFileHandlerTest";
36
37     private final ProjectData a = new ProjectData();
38     private File JavaDoc tmpDir = new File JavaDoc(pathToTestOutput);
39
40     public void setUp()
41     {
42         // Create some coverage data
43
ClassData classData;
44         assertEquals(0, a.getNumberOfClasses());
45         assertEquals(0, a.getNumberOfChildren());
46
47         classData = new ClassData("HelloWorld");
48         classData.setSourceFileName("com/example/HelloWorld.java");
49         for (int i = 0; i < 10; i++)
50             classData.addLine(i, "test", "(I)B");
51         a.addClassData(classData);
52         assertEquals(1, a.getNumberOfClasses());
53         assertEquals(1, a.getNumberOfChildren());
54
55         classData = new ClassData("HelloWorldHelper");
56         classData.setSourceFileName("com/example/HelloWorldHelper.java");
57         for (int i = 0; i < 14; i++)
58             classData.addLine(i, "test", "(I)B");
59         a.addClassData(classData);
60         assertEquals(2, a.getNumberOfClasses());
61         assertEquals(1, a.getNumberOfChildren());
62
63         // Create the directory for our serialized coverage data
64
tmpDir.mkdirs();
65     }
66
67     public void tearDown()
68     {
69         tmpDir = new File JavaDoc(pathToTestOutput);
70         File JavaDoc files[] = tmpDir.listFiles();
71         for (int i = 0; i < files.length; i++)
72             files[i].delete();
73         tmpDir.delete();
74     }
75
76     public void testSaveAndRestore()
77     {
78         File JavaDoc dataFile = new File JavaDoc(tmpDir, CoverageDataFileHandler.FILE_NAME);
79         CoverageDataFileHandler.saveCoverageData(a, dataFile);
80
81         ProjectData b;
82         b = CoverageDataFileHandler.loadCoverageData(dataFile);
83         assertEquals(a, b);
84     }
85
86 }
87
Popular Tags