1 package org.hansel; 2 3 import java.util.Arrays ; 4 import java.util.HashSet ; 5 6 import junit.framework.TestResult; 7 import junit.framework.TestSuite; 8 9 import org.hansel.probes.ProbeFilter; 10 11 20 public class CoverageDecorator extends TestSuite { 21 private String [] classNamesCovered; 22 private Class [] classesCovered; 23 24 26 private ProbeTable probeTable; 27 28 33 public CoverageDecorator(Class [] classesCovered) { 34 this(classesCovered, null); 35 } 36 37 42 public CoverageDecorator(Class [] classesCovered, 43 ProbeFilter probeFilter) { 44 patchTestClassLoader(); 45 this.classesCovered = classesCovered; 46 this.classNamesCovered = new String [classesCovered.length]; 47 for (int i=0; i<classNamesCovered.length; i++) { 48 this.classNamesCovered[i] = classesCovered[i].getName(); 49 } 50 this.probeTable = new ProbeTable(probeFilter); 51 } 52 53 private void patchTestClassLoader() { 54 69 } 70 78 public CoverageDecorator(Class testClass, Class [] classesCovered) { 79 this(classesCovered); 80 81 addTestSuite(testClass); 82 } 83 84 92 public CoverageDecorator(Class testClass, 93 Class [] classesCovered, 94 ProbeFilter probeFilter) { 95 this(classesCovered, probeFilter); 96 97 addTestSuite(testClass); 98 } 99 100 public void setDisplayStatistics(boolean display) { 101 probeTable.setDisplayStatistics(display); 102 } 103 104 public Class [] getClassesCovered() { 105 return classesCovered; 106 } 107 108 protected ProbeTable getProbeTable() { 109 return probeTable; 110 } 111 112 protected void superRun(TestResult result) { 113 super.run(result); 114 } 115 116 protected boolean init(TestResult result) { 117 ProbeTable.setProbeTable(probeTable); 118 119 try { 120 Startup.init(new HashSet <String >(Arrays.asList(classNamesCovered))); 121 } catch (Exception e) { 122 result.addError(this, e); 123 return false; 124 } 125 126 return true; 127 } 128 129 protected void shutdown(TestResult result) { 130 try { 131 loadClasses(); 132 Startup.tearDown(); 133 134 probeTable.run(result); 135 } catch (Exception e) { 136 result.addError(this, e); 137 } 138 } 139 140 public void run(TestResult result) { 141 if (!init(result)) { 143 return; 144 } 145 146 super.run(result); 147 148 shutdown(result); 149 } 151 152 private void loadClasses() { 153 for (int i=0; i<classesCovered.length; i++) { 155 classesCovered[i].getDeclaredFields(); 156 } 157 } 158 159 public String toString() { 160 return "Coverage Decorator"; 161 } 162 } 163 | Popular Tags |