1 21 22 package net.sourceforge.cobertura.coveragedata; 23 24 import java.io.File ; 25 26 import junit.framework.TestCase; 27 28 public class CoverageDataFileHandlerTest extends TestCase 29 { 30 31 private final static String basedir = (System.getProperty("basedir") != null) 32 ? System.getProperty("basedir") 33 : "."; 34 private final static String pathToTestOutput = basedir 35 + "/build/test/CoverageDataFileHandlerTest"; 36 37 private final ProjectData a = new ProjectData(); 38 private File tmpDir = new File (pathToTestOutput); 39 40 public void setUp() 41 { 42 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 tmpDir.mkdirs(); 65 } 66 67 public void tearDown() 68 { 69 tmpDir = new File (pathToTestOutput); 70 File 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 dataFile = new File (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 |