1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
package org.apache.maven.surefire.junitcore; |
21 | |
|
22 | |
import org.apache.maven.surefire.report.ReporterException; |
23 | |
import org.apache.maven.surefire.report.ReporterManagerFactory; |
24 | |
import org.apache.maven.surefire.suite.SurefireTestSuite; |
25 | |
import org.apache.maven.surefire.testset.TestSetFailedException; |
26 | |
import org.apache.maven.surefire.util.SurefireDirectoryScanner; |
27 | |
|
28 | |
import java.io.File; |
29 | |
import java.util.ArrayList; |
30 | |
import java.util.Map; |
31 | |
import java.util.Properties; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
@SuppressWarnings( { "UnusedDeclaration" } ) |
40 | |
public class JUnitCoreDirectoryTestSuite |
41 | |
implements SurefireTestSuite |
42 | |
{ |
43 | |
private final SurefireDirectoryScanner directoryScanner; |
44 | |
|
45 | |
private TestsToRun testsToRun; |
46 | |
|
47 | |
protected Map testSets; |
48 | |
|
49 | |
private final JUnitCoreParameters jUnitCoreParameters; |
50 | |
|
51 | |
|
52 | |
public JUnitCoreDirectoryTestSuite( File basedir, ArrayList includes, ArrayList excludes, Properties properties ) |
53 | 0 | { |
54 | 0 | directoryScanner = new SurefireDirectoryScanner( basedir, includes, excludes ); |
55 | 0 | this.jUnitCoreParameters = new JUnitCoreParameters( properties ); |
56 | 0 | } |
57 | |
|
58 | |
|
59 | |
public void execute( ReporterManagerFactory reporterManagerFactory, ClassLoader classLoader ) |
60 | |
throws ReporterException, TestSetFailedException |
61 | |
{ |
62 | 0 | if ( testsToRun == null ) |
63 | |
{ |
64 | 0 | throw new IllegalStateException( "You must call locateTestSets before calling execute" ); |
65 | |
} |
66 | |
|
67 | 0 | JUnitCoreTestSet.execute( testsToRun.getLocatedClasses(), reporterManagerFactory, jUnitCoreParameters ); |
68 | 0 | } |
69 | |
|
70 | |
public void execute( String testSetName, ReporterManagerFactory reporterManagerFactory, ClassLoader classLoader ) |
71 | |
throws ReporterException, TestSetFailedException |
72 | |
{ |
73 | 0 | if ( testsToRun == null ) |
74 | |
{ |
75 | 0 | throw new IllegalStateException( "You must call locateTestSets before calling execute" ); |
76 | |
} |
77 | 0 | JUnitCoreTestSet testSet = testsToRun.getTestSet( testSetName ); |
78 | |
|
79 | |
|
80 | 0 | if ( testSet == null ) |
81 | |
{ |
82 | 0 | throw new TestSetFailedException( "Unable to find test set '" + testSetName + "' in suite" ); |
83 | |
} |
84 | 0 | testSet.execute( reporterManagerFactory, jUnitCoreParameters ); |
85 | 0 | } |
86 | |
|
87 | |
public Map locateTestSets( ClassLoader classLoader ) |
88 | |
throws TestSetFailedException |
89 | |
{ |
90 | 0 | if ( testSets != null ) |
91 | |
{ |
92 | 0 | throw new IllegalStateException( "You can't call locateTestSets twice" ); |
93 | |
} |
94 | |
|
95 | 0 | Class[] locatedClasses = directoryScanner.locateTestClasses( classLoader ); |
96 | 0 | testsToRun = new TestsToRun( locatedClasses ); |
97 | 0 | return testsToRun.getTestSets(); |
98 | |
} |
99 | |
|
100 | |
public int getNumTests() |
101 | |
{ |
102 | 0 | if ( testsToRun == null ) |
103 | |
{ |
104 | 0 | throw new IllegalStateException( "You must call locateTestSets before calling getNumTests" ); |
105 | |
} |
106 | 0 | return testsToRun.size(); |
107 | |
} |
108 | |
} |