Coverage Report - org.apache.maven.surefire.junit.JUnitDirectoryTestSuite
 
Classes in this File Line Coverage Branch Coverage Complexity
JUnitDirectoryTestSuite
0%
0/17
0%
0/8
3
 
 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 junit.framework.Test;
 23  
 import org.apache.maven.surefire.suite.AbstractDirectoryTestSuite;
 24  
 import org.apache.maven.surefire.testset.PojoTestSet;
 25  
 import org.apache.maven.surefire.testset.SurefireTestSet;
 26  
 import org.apache.maven.surefire.testset.TestSetFailedException;
 27  
 
 28  
 import java.io.File;
 29  
 import java.util.ArrayList;
 30  
 
 31  
 /**
 32  
  * Test suite for JUnit tests based on a directory of Java test classes.
 33  
  *
 34  
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
 35  
  */
 36  
 public class JUnitDirectoryTestSuite
 37  
     extends AbstractDirectoryTestSuite
 38  
 {
 39  
     public JUnitDirectoryTestSuite( File basedir, ArrayList includes, ArrayList excludes )
 40  
     {
 41  0
         super( basedir, includes, excludes );
 42  0
     }
 43  
 
 44  
     protected SurefireTestSet createTestSet( Class testClass, ClassLoader classLoader )
 45  
         throws TestSetFailedException
 46  
     {
 47  0
         Class junitClass = null;
 48  
         try
 49  
         {
 50  0
             junitClass = classLoader.loadClass( Test.class.getName() );
 51  
         }
 52  0
         catch ( NoClassDefFoundError e)
 53  
         {
 54  
             // ignore this
 55  
         }
 56  0
         catch ( ClassNotFoundException e )
 57  
         {
 58  
             // ignore this
 59  0
         }
 60  
 
 61  
         SurefireTestSet testSet;
 62  0
         if ( junitClass != null && junitClass.isAssignableFrom( testClass ) )
 63  
         {
 64  0
             testSet = new JUnitTestSet( testClass );
 65  
         }
 66  0
         else if (classHasPublicNoArgConstructor( testClass ))
 67  
         {
 68  0
             testSet = new PojoTestSet( testClass );
 69  
         }
 70  
         else
 71  
         {
 72  0
             testSet = null;
 73  
         }
 74  0
         return testSet;
 75  
     }
 76  
 
 77  
     private boolean classHasPublicNoArgConstructor( Class testClass )
 78  
     {
 79  
         try
 80  
         {
 81  0
             testClass.getConstructor( new Class[0] );
 82  0
             return true;
 83  
         }
 84  0
         catch ( Exception e )
 85  
         {
 86  0
             return false;
 87  
         }
 88  
     }
 89  
 }