1 package org.apache.maven.surefire.junit;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.Test;
23 import junit.framework.TestCase;
24 import junit.framework.TestSuite;
25 import org.apache.maven.surefire.common.junit3.JUnit3Reflector;
26 import org.apache.maven.surefire.report.ReportEntry;
27 import org.apache.maven.surefire.report.RunListener;
28 import org.apache.maven.surefire.report.TestSetReportEntry;
29 import org.apache.maven.surefire.testset.TestSetFailedException;
30
31 import java.util.ArrayList;
32 import java.util.List;
33
34 public class JUnitTestSetTest
35 extends TestCase
36 {
37
38 public void testExecuteSuiteClass()
39 throws TestSetFailedException
40 {
41 ClassLoader testClassLoader = this.getClass().getClassLoader();
42 JUnit3Reflector reflector = new JUnit3Reflector( testClassLoader );
43 JUnitTestSet testSet = new JUnitTestSet( Suite.class, reflector );
44 SuccessListener listener = new SuccessListener();
45 testSet.execute( listener, testClassLoader );
46 List succeededTests = listener.getSucceededTests();
47 assertEquals( 1, succeededTests.size() );
48 assertEquals( "testSuccess(org.apache.maven.surefire.junit.JUnitTestSetTest$AlwaysSucceeds)",
49 ( (ReportEntry) succeededTests.get( 0 ) ).getName() );
50 }
51
52 public static final class AlwaysSucceeds
53 extends TestCase
54 {
55 public void testSuccess()
56 {
57 assertTrue( true );
58 }
59 }
60
61 public static class SuccessListener
62 implements RunListener
63 {
64
65 private List<ReportEntry> succeededTests = new ArrayList<ReportEntry>();
66
67 @Override
68 public void testSetStarting( TestSetReportEntry report )
69 {
70 }
71
72 @Override
73 public void testSetCompleted( TestSetReportEntry report )
74 {
75 }
76
77 @Override
78 public void testStarting( ReportEntry report )
79 {
80 }
81
82 @Override
83 public void testSucceeded( ReportEntry report )
84 {
85 this.succeededTests.add( report );
86 }
87
88 @Override
89 public void testAssumptionFailure( ReportEntry report )
90 {
91 throw new IllegalStateException();
92 }
93
94 @Override
95 public void testError( ReportEntry report )
96 {
97 throw new IllegalStateException();
98 }
99
100 @Override
101 public void testFailed( ReportEntry report )
102 {
103 throw new IllegalStateException();
104 }
105
106 @Override
107 public void testSkipped( ReportEntry report )
108 {
109 throw new IllegalStateException();
110 }
111
112 @Override
113 public void testExecutionSkippedByUser()
114 {
115 }
116
117 public void testSkippedByUser( ReportEntry report )
118 {
119 testSkipped( report );
120 }
121
122 public List getSucceededTests()
123 {
124 return succeededTests;
125 }
126
127 }
128
129 public static class Suite
130 {
131
132 public static Test suite()
133 {
134 TestSuite suite = new TestSuite();
135 suite.addTestSuite( AlwaysSucceeds.class );
136 return suite;
137 }
138 }
139 }