1 54 55 package junitx.util; 56 57 import junit.framework.Test; 58 import junit.framework.TestSuite; 59 60 import java.util.Enumeration ; 61 import java.util.List ; 62 import java.util.Vector ; 63 import java.util.zip.ZipEntry ; 64 import java.util.zip.ZipFile ; 65 66 102 public class ArchiveSuiteBuilder 103 extends AbstractSuiteBuilder { 104 105 108 public ArchiveSuiteBuilder() { 109 this(null); 110 } 111 112 115 public ArchiveSuiteBuilder(TestFilter filter) { 116 super(filter); 117 } 118 119 123 public Test suite(ZipFile file) 124 throws Exception { 125 TestSuite suite = new TestSuite(file.getName()); 126 127 List classnames = browse(file); 128 merge(classnames, suite); 129 130 return suite; 131 } 132 133 137 public Test suite(String filename) 138 throws Exception { 139 ZipFile file = new ZipFile (filename); 140 Test result; 141 142 try { 143 result = suite(file); 144 } finally { 145 file.close(); 146 } 147 148 return result; 149 } 150 151 157 protected List browse(ZipFile file) { 158 List result = new Vector (); 159 Enumeration entries = file.entries(); 160 while (entries.hasMoreElements()) { 161 ZipEntry entry = (ZipEntry ) entries.nextElement(); 162 if (!entry.isDirectory()) { 163 if (isTestClass(entry.getName())) { 164 166 String classname = entry.getName().replace('/', '.'); 167 classname = classname.substring(0, classname.length() - 6); 168 result.add(classname); 169 } 170 } 171 } 172 return result; 173 } 174 175 } 176 | Popular Tags |