1 6 21 22 package de.schlichtherle.junit.runner; 23 24 import de.schlichtherle.io.*; 25 26 import java.util.*; 27 28 import junit.runner.TestCollector; 29 30 35 public class TrueZIPTestCollector implements TestCollector { 36 37 private static final int SUFFIX_LENGTH = ".class".length(); 38 39 private final List tests = new LinkedList(); 40 41 42 public TrueZIPTestCollector() { 43 final String [] cp = System.getProperty("java.class.path").split( 44 System.getProperty("path.separator")); 45 for (int i = 0; i < cp.length; i++) { 46 scan(new File(cp[i], ArchiveDetector.DEFAULT), ""); } 48 } 49 50 private void scan(final File root, final String path) { 51 final File file = new File(root, path); 52 if (file.isDirectory()) { 53 final String [] children = file.list(); 54 for (int i = 0; i < children.length; i++) 55 scan(root, path + File.separator + children[i]); 56 } else if (file.isFile()) { 57 if (isTestClass(path)) 58 tests.add(toClassName(path)); 59 } 60 } 61 62 protected boolean isTestClass(String path) { 63 return path.endsWith("Test.class") && 64 path.indexOf("junit" + File.separator) < 0 && 65 path.indexOf('$') < 0; 66 } 67 68 protected String toClassName(String path) { 69 return path.substring(1, path.length() - SUFFIX_LENGTH) 70 .replace(File.separatorChar, '.'); 71 } 72 73 public Enumeration collectTests() { 74 return Collections.enumeration(tests); 75 } 76 } 77 | Popular Tags |