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