1
package org.hibernate.test;
4
import java.util.HashSet;
7
import org.apache.tools.ant.types.selectors.FileSelector;
8
import org.apache.tools.ant.BuildException;
10
import org.hibernate.junit.TestSuiteVisitor;
12
import junit.framework.Test;
13
import junit.framework.TestSuite;
16
* A custom Ant FileSelector used to limit the tests run from the Ant
17
* build script to only those defined in the {@link org.hibernate.test.AllTests} suite.
19
* {@link org.hibernate.test.AllTests} is used/maintained by the developers to easily
20
* run the test suite in all IDEs. It represents all the tests
21
* which should actually be run and included in test results.
23
* @author Steve Ebersole
25
public class TestSelector implements FileSelector {
27
private final Set allTestClassNames = new HashSet();
29
public TestSelector() {
30
TestSuiteVisitor.Handler handler = new TestSuiteVisitor.Handler() {
31
public void handleTestCase(Test test) {
32
allTestClassNames.add( test.getClass().getName() );
34
public void startingTestSuite(TestSuite suite) {}
35
public void completedTestSuite(TestSuite suite) {}
37
TestSuiteVisitor visitor = new TestSuiteVisitor( handler );
38
visitor.visit( ( TestSuite ) AllTests.suite() );
42
// FileSelector impl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44
public boolean isSelected(File dir, String fileFromDir, File fullFile) throws BuildException {
45
String correspondingClassName = determineClassName( fileFromDir );
46
return allTestClassNames.contains( correspondingClassName );
49
private String determineClassName(String file) {
50
if ( file.endsWith( ".class" ) ) {
51
file = file.substring( 0, file.length() - 6 );
53
else if ( file.endsWith( ".java" ) ) {
54
file = file.substring( 0, file.length() - 5 );
59
file = file.replace( '\\', '.' );
60
file = file.replace( '/', '.' );