~ubuntu-branches/ubuntu/wily/libhibernate3-java/wily-proposed

« back to all changes in this revision

Viewing changes to test/org/hibernate/test/TestSelector.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-10-14 14:43:34 UTC
  • Revision ID: james.westby@ubuntu.com-20071014144334-eamc8i0q10gs1aro
Tags: upstream-3.2.5
ImportĀ upstreamĀ versionĀ 3.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.hibernate.test;
 
2
 
 
3
import java.util.Set;
 
4
import java.util.HashSet;
 
5
import java.io.File;
 
6
 
 
7
import org.apache.tools.ant.types.selectors.FileSelector;
 
8
import org.apache.tools.ant.BuildException;
 
9
 
 
10
import org.hibernate.junit.TestSuiteVisitor;
 
11
 
 
12
import junit.framework.Test;
 
13
import junit.framework.TestSuite;
 
14
 
 
15
/**
 
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.
 
18
 * <p/>
 
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.
 
22
 *
 
23
 * @author Steve Ebersole
 
24
 */
 
25
public class TestSelector implements FileSelector {
 
26
 
 
27
        private final Set allTestClassNames = new HashSet();
 
28
 
 
29
        public TestSelector() {
 
30
                TestSuiteVisitor.Handler handler = new TestSuiteVisitor.Handler() {
 
31
                        public void handleTestCase(Test test) {
 
32
                                allTestClassNames.add( test.getClass().getName() );
 
33
                        }
 
34
                        public void startingTestSuite(TestSuite suite) {}
 
35
                        public void completedTestSuite(TestSuite suite) {}
 
36
                };
 
37
                TestSuiteVisitor visitor = new TestSuiteVisitor( handler );
 
38
                visitor.visit( ( TestSuite ) AllTests.suite() );
 
39
        }
 
40
 
 
41
 
 
42
        // FileSelector impl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
43
 
 
44
        public boolean isSelected(File dir, String fileFromDir, File fullFile) throws BuildException {
 
45
                String correspondingClassName = determineClassName( fileFromDir );
 
46
                return allTestClassNames.contains( correspondingClassName );
 
47
        }
 
48
 
 
49
        private String determineClassName(String file) {
 
50
                if ( file.endsWith( ".class" ) ) {
 
51
                        file = file.substring( 0, file.length() - 6 );
 
52
                }
 
53
                else if ( file.endsWith( ".java" ) ) {
 
54
                        file = file.substring( 0, file.length() - 5 );
 
55
                }
 
56
                else {
 
57
                        return null;
 
58
                }
 
59
                file = file.replace( '\\', '.' );
 
60
                file = file.replace( '/', '.' );
 
61
                return file;
 
62
        }
 
63
 
 
64
}