Coverage Report - org.apache.maven.surefire.junit.JUnitTestSet
 
Classes in this File Line Coverage Branch Coverage Complexity
JUnitTestSet
0%
0/32
0%
0/4
4.25
 
 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 org.apache.maven.surefire.common.junit3.JUnit3Reflector;
 23  
 import org.apache.maven.surefire.report.RunListener;
 24  
 import org.apache.maven.surefire.testset.TestSetFailedException;
 25  
 
 26  
 import java.lang.reflect.InvocationTargetException;
 27  
 import java.lang.reflect.Method;
 28  
 import java.lang.reflect.Proxy;
 29  
 
 30  
 public final class JUnitTestSet
 31  
     implements SurefireTestSet
 32  
 {
 33  
     private final Class testClass;
 34  
 
 35  
     private final JUnit3Reflector reflector;
 36  
 
 37  
     public JUnitTestSet( Class testClass, JUnit3Reflector reflector )
 38  
         throws TestSetFailedException
 39  0
     {
 40  0
         if ( testClass == null )
 41  
         {
 42  0
             throw new NullPointerException( "testClass is null" );
 43  
         }
 44  
 
 45  0
         this.testClass = testClass;
 46  0
         this.reflector = reflector;
 47  
 
 48  
         // ----------------------------------------------------------------------
 49  
         // Strategy for executing JUnit tests
 50  
         //
 51  
         // o look for the suite method and if that is present execute that method
 52  
         //   to get the test object.
 53  
         //
 54  
         // o look for test classes that are assignable from TestCase
 55  
         //
 56  
         // o look for test classes that only implement the Test interface
 57  
         // ----------------------------------------------------------------------
 58  
 
 59  
         // The interface implemented by the dynamic proxy (TestListener), happens to be
 60  
         // the same as the param types of TestResult.addTestListener
 61  0
     }
 62  
 
 63  
 
 64  
     public void execute( RunListener reporter, ClassLoader loader )
 65  
         throws TestSetFailedException
 66  
     {
 67  0
         Class testClass = getTestClass();
 68  
 
 69  
         try
 70  
         {
 71  0
             Object testObject = reflector.constructTestObject( testClass );
 72  
             final Method runMethod;
 73  
 
 74  0
             if ( this.reflector.getTestInterface().isAssignableFrom( testObject.getClass() ) )
 75  
             {
 76  0
                 runMethod = this.reflector.getTestInterfaceRunMethod();
 77  
             }
 78  
             else
 79  
             {
 80  0
                 runMethod = reflector.getRunMethod( this.testClass );
 81  
             }
 82  
 
 83  0
             Object instanceOfTestResult = reflector.getTestResultClass().newInstance();
 84  
 
 85  0
             TestListenerInvocationHandler invocationHandler = new TestListenerInvocationHandler( reporter );
 86  
 
 87  0
             Object testListener =
 88  
                 Proxy.newProxyInstance( loader, reflector.getInterfacesImplementedByDynamicProxy(), invocationHandler );
 89  
 
 90  0
             Object[] addTestListenerParams = { testListener };
 91  
 
 92  0
             reflector.getAddListenerMethod().invoke( instanceOfTestResult, addTestListenerParams );
 93  
 
 94  0
             Object[] runParams = { instanceOfTestResult };
 95  
 
 96  0
             runMethod.invoke( testObject, runParams );
 97  
         }
 98  0
         catch ( IllegalArgumentException e )
 99  
         {
 100  0
             throw new TestSetFailedException( testClass.getName(), e );
 101  
         }
 102  0
         catch ( InstantiationException e )
 103  
         {
 104  0
             throw new TestSetFailedException( testClass.getName(), e );
 105  
         }
 106  0
         catch ( IllegalAccessException e )
 107  
         {
 108  0
             throw new TestSetFailedException( testClass.getName(), e );
 109  
         }
 110  0
         catch ( InvocationTargetException e )
 111  
         {
 112  0
             throw new TestSetFailedException( testClass.getName(), e.getTargetException() );
 113  
         }
 114  0
         catch ( NoSuchMethodException e )
 115  
         {
 116  0
             throw new TestSetFailedException( "Class is not a JUnit TestCase", e );
 117  0
         }
 118  0
     }
 119  
 
 120  
     public String getName()
 121  
     {
 122  0
         return testClass.getName();
 123  
     }
 124  
 
 125  
     Class getTestClass()
 126  
     {
 127  0
         return testClass;
 128  
     }
 129  
 }