View Javadoc
1   package org.apache.maven.surefire.junit;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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 }