1. package coverage;
  2.  
  3. import java.io.*;
  4. import org.junit.Test;
  5. import net.sourceforge.cobertura.coveragedata.*;
  6.  
  7. public class CoverItAll
  8. {
  9.     @Test
  10.     public void coverItAll() throws Exception {
  11.         File cdf = CoverageDataFileHandler.getDefaultDataFile();
  12.         if (cdf.exists()) {
  13.             ObjectInputStream ois = new ObjectInputStream(new FileInputStream(CoverageDataFileHandler.getDefaultDataFile()));
  14.             ProjectData pd = (ProjectData) ois.readObject();
  15.             ois.close();
  16.             for(Object cd_ : pd.getClasses()) {
  17.                 ClassData cd = (ClassData) cd_;
  18.                 String name = cd.getName();
  19.                 for(CoverageData _line : cd.getLines()) {
  20.                     LineData line = (LineData) _line;
  21.                     int lino = line.getLineNumber();
  22.                     for (int i = 0; i < line.getConditionSize(); i++) {
  23.                         Object cond = line.getConditionData(i);
  24.                         if (cond instanceof JumpData) {
  25.                             JumpData jmp = (JumpData) cond;
  26.                             int jmpno = jmp.getConditionNumber();
  27.                             TouchCollector.touch(name, lino);
  28.                             TouchCollector.touchJump(name, lino, jmpno, false);
  29.                             TouchCollector.touch(name, lino);
  30.                             TouchCollector.touchJump(name, lino, jmpno, true);                         
  31.                         } else if (cond instanceof SwitchData) {
  32.                             SwitchData swi = (SwitchData) cond;
  33.                             int swino = swi.getSwitchNumber();
  34.                             TouchCollector.touch(name, lino);
  35.                             TouchCollector.touchSwitch(name, lino, swino, -1);
  36.                             for(int j=0; j<swi.getNumberOfValidBranches(); j++) {
  37.                                 TouchCollector.touch(name, lino);
  38.                                 TouchCollector.touchSwitch(name, lino, swino, j);
  39.                             }
  40.                         }
  41.                     }
  42.                     if (line.getConditionSize() == 0)
  43.                         TouchCollector.touch(name, lino);
  44.                 }
  45.             }
  46.         }
  47.     }
  48. }
  49.  
  50.