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 java.util.ArrayList;
23 import java.util.List;
24 import org.apache.maven.surefire.common.junit3.JUnit3Reflector;
25 import org.apache.maven.surefire.report.ReportEntry;
26 import org.apache.maven.surefire.report.RunListener;
27 import org.apache.maven.surefire.testset.TestSetFailedException;
28
29 import junit.framework.Test;
30 import junit.framework.TestCase;
31 import junit.framework.TestSuite;
32
33 public class JUnitTestSetTest
34 extends TestCase
35 {
36
37 public void testExecuteSuiteClass()
38 throws TestSetFailedException
39 {
40 ClassLoader testClassLoader = this.getClass().getClassLoader();
41 JUnit3Reflector reflector = new JUnit3Reflector( testClassLoader );
42 JUnitTestSet testSet = new JUnitTestSet( Suite.class, reflector );
43 SuccessListener listener = new SuccessListener();
44 testSet.execute( listener, testClassLoader );
45 List succeededTests = listener.getSucceededTests();
46 assertEquals( 1, succeededTests.size() );
47 assertEquals( "testSuccess(org.apache.maven.surefire.junit.JUnitTestSetTest$AlwaysSucceeds)",
48 ( (ReportEntry) succeededTests.get( 0 ) ).getName() );
49 }
50
51 public static final class AlwaysSucceeds
52 extends TestCase
53 {
54 public void testSuccess()
55 {
56 assertTrue( true );
57 }
58 }
59
60 public static class SuccessListener
61 implements RunListener
62 {
63
64 private List<ReportEntry> succeededTests = new ArrayList<ReportEntry>();
65
66 public void testSetStarting( ReportEntry report )
67 {
68 }
69
70 public void testSetCompleted( ReportEntry report )
71 {
72 }
73
74 public void testStarting( ReportEntry report )
75 {
76 }
77
78 public void testSucceeded( ReportEntry report )
79 {
80 this.succeededTests.add( report );
81 }
82
83 public void testAssumptionFailure( ReportEntry report )
84 {
85 throw new IllegalStateException();
86 }
87
88 public void testError( ReportEntry report )
89 {
90 throw new IllegalStateException();
91 }
92
93 public void testFailed( ReportEntry report )
94 {
95 throw new IllegalStateException();
96 }
97
98 public void testSkipped( ReportEntry report )
99 {
100 throw new IllegalStateException();
101 }
102
103 public List getSucceededTests()
104 {
105 return succeededTests;
106 }
107
108 }
109
110 public static class Suite
111 {
112
113 public static Test suite()
114 {
115 TestSuite suite = new TestSuite();
116 suite.addTestSuite( AlwaysSucceeds.class );
117 return suite;
118 }
119 }
120 }