1 21 package net.sourceforge.cobertura.merge; 22 23 import java.util.List ; 24 import java.io.File ; 25 import java.io.IOException ; 26 import java.util.ArrayList ; 27 28 import junit.framework.TestCase; 29 import net.sourceforge.cobertura.coveragedata.ClassData; 30 import net.sourceforge.cobertura.coveragedata.CoverageDataFileHandler; 31 import net.sourceforge.cobertura.coveragedata.ProjectData; 32 33 36 public class MergeMainTest extends TestCase { 37 private ClassData firstClass = new ClassData("test.First"); 38 private ClassData secondClass = new ClassData("test.Second"); 39 private ClassData seventhClass = new ClassData("Seventh"); 40 41 private ProjectData greenProject = new ProjectData(); 42 private ProjectData redProject = new ProjectData(); 43 private ProjectData blueProject = new ProjectData(); 44 45 private List filesToRemove = new ArrayList (); 46 47 private File createTempSerFile() throws IOException { 48 File result = File.createTempFile( "cobertura", ".ser"); 49 result.delete(); 50 filesToRemove.add(result); 51 return result; 52 } 53 54 protected void tearDown() throws Exception { 55 for( int i=0; i<filesToRemove.size(); i++) { 56 ((File )filesToRemove.get(i)).delete(); 57 } 58 } 59 60 public void testNewDestinationFile() throws IOException { 61 greenProject.addClassData( firstClass); 63 redProject.addClassData( secondClass); 64 redProject.addClassData( seventhClass); 65 66 File greenFile = createTempSerFile(); 68 File redFile = createTempSerFile(); 69 File dataFile = createTempSerFile(); 70 71 CoverageDataFileHandler.saveCoverageData( greenProject, greenFile); 73 CoverageDataFileHandler.saveCoverageData( redProject, redFile); 74 75 String [] args = {"--datafile", dataFile.getAbsolutePath(), 77 greenFile.getAbsolutePath(), redFile.getAbsolutePath()}; 78 79 Main.main( args); 80 81 ProjectData merged = CoverageDataFileHandler.loadCoverageData( dataFile); 83 84 assertEquals( 3, merged.getNumberOfClasses()); 86 assertNotNull( merged.getClassData("test.First")); 87 assertNotNull( merged.getClassData("test.Second")); 88 assertNotNull( merged.getClassData("Seventh")); 89 assertNull( merged.getClassData("test.Third")); 90 } 91 92 public void testExistingDestinationFile() throws IOException { 93 greenProject.addClassData( firstClass); 95 redProject.addClassData( secondClass); 96 97 File greenFile = createTempSerFile(); 99 File dataFile = createTempSerFile(); 100 101 CoverageDataFileHandler.saveCoverageData( greenProject, greenFile); 103 CoverageDataFileHandler.saveCoverageData( redProject, dataFile); 104 105 String [] args = {"--datafile", dataFile.getAbsolutePath(), 107 greenFile.getAbsolutePath()}; 108 109 Main.main( args); 110 111 ProjectData merged = CoverageDataFileHandler.loadCoverageData( dataFile); 113 114 assertEquals( 2, merged.getNumberOfClasses()); 116 assertNotNull( merged.getClassData("test.First")); 117 assertNotNull( merged.getClassData("test.Second")); 118 } 119 120 public void testBaseDir() throws IOException { 121 greenProject.addClassData( firstClass); 123 redProject.addClassData( seventhClass); 124 blueProject.addClassData( secondClass); 125 126 File greenFile = createTempSerFile(); 128 File redFile = createTempSerFile(); 129 File blueFile = createTempSerFile(); 130 File dataFile = createTempSerFile(); 131 132 dataFile.delete(); 133 134 CoverageDataFileHandler.saveCoverageData( greenProject, greenFile); 136 CoverageDataFileHandler.saveCoverageData( redProject, redFile); 137 CoverageDataFileHandler.saveCoverageData( blueProject, blueFile); 138 139 String [] args = {"--datafile", dataFile.getAbsolutePath(), 141 greenFile.getAbsolutePath(), 142 "--basedir", redFile.getParent(), redFile.getName(), blueFile.getName()}; 143 144 Main.main( args); 145 146 ProjectData merged = CoverageDataFileHandler.loadCoverageData( dataFile); 148 149 assertEquals( 3, merged.getNumberOfClasses()); 151 assertNotNull( merged.getClassData("test.First")); 152 assertNotNull( merged.getClassData("test.Second")); 153 assertNotNull( merged.getClassData("Seventh")); 154 } 155 } 156 | Popular Tags |