Coverage Report - org.apache.maven.surefire.junitcore.JUnitCoreDirectoryTestSuite
 
Classes in this File Line Coverage Branch Coverage Complexity
JUnitCoreDirectoryTestSuite
0%
0/23
0%
0/10
0
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 
 20  
 package org.apache.maven.surefire.junitcore;
 21  
 
 22  
 import org.apache.maven.surefire.report.ReporterException;
 23  
 import org.apache.maven.surefire.report.ReporterManagerFactory;
 24  
 import org.apache.maven.surefire.suite.SurefireTestSuite;
 25  
 import org.apache.maven.surefire.testset.TestSetFailedException;
 26  
 import org.apache.maven.surefire.util.SurefireDirectoryScanner;
 27  
 
 28  
 import java.io.File;
 29  
 import java.util.ArrayList;
 30  
 import java.util.Map;
 31  
 import java.util.Properties;
 32  
 
 33  
 /**
 34  
  * Test suite for JUnitCore based on a directory of Java test classes.
 35  
  *
 36  
  * @author Karl M. Davis
 37  
  * @author Kristian Rosenvold (junit core adaption)
 38  
  */
 39  
 @SuppressWarnings( { "UnusedDeclaration" } )
 40  
 public class JUnitCoreDirectoryTestSuite
 41  
     implements SurefireTestSuite
 42  
 {
 43  
     private final SurefireDirectoryScanner directoryScanner;
 44  
 
 45  
     private TestsToRun testsToRun;
 46  
 
 47  
     protected Map testSets;
 48  
 
 49  
     private final JUnitCoreParameters jUnitCoreParameters;
 50  
 
 51  
 
 52  
     public JUnitCoreDirectoryTestSuite( File basedir, ArrayList includes, ArrayList excludes, Properties properties )
 53  0
     {
 54  0
         directoryScanner = new SurefireDirectoryScanner( basedir, includes, excludes );
 55  0
         this.jUnitCoreParameters = new JUnitCoreParameters( properties );
 56  0
     }
 57  
 
 58  
 
 59  
     public void execute( ReporterManagerFactory reporterManagerFactory, ClassLoader classLoader )
 60  
         throws ReporterException, TestSetFailedException
 61  
     {
 62  0
         if ( testsToRun == null )
 63  
         {
 64  0
             throw new IllegalStateException( "You must call locateTestSets before calling execute" );
 65  
         }
 66  
 
 67  0
         JUnitCoreTestSet.execute( testsToRun.getLocatedClasses(), reporterManagerFactory, jUnitCoreParameters );
 68  0
     }
 69  
 
 70  
     public void execute( String testSetName, ReporterManagerFactory reporterManagerFactory, ClassLoader classLoader )
 71  
         throws ReporterException, TestSetFailedException
 72  
     {
 73  0
         if ( testsToRun == null )
 74  
         {
 75  0
             throw new IllegalStateException( "You must call locateTestSets before calling execute" );
 76  
         }
 77  0
         JUnitCoreTestSet testSet = testsToRun.getTestSet( testSetName );
 78  
 
 79  
 
 80  0
         if ( testSet == null )
 81  
         {
 82  0
             throw new TestSetFailedException( "Unable to find test set '" + testSetName + "' in suite" );
 83  
         }
 84  0
         testSet.execute( reporterManagerFactory, jUnitCoreParameters );
 85  0
     }
 86  
 
 87  
     public Map locateTestSets( ClassLoader classLoader )
 88  
         throws TestSetFailedException
 89  
     {
 90  0
         if ( testSets != null )
 91  
         {
 92  0
             throw new IllegalStateException( "You can't call locateTestSets twice" );
 93  
         }
 94  
 
 95  0
         Class[] locatedClasses = directoryScanner.locateTestClasses( classLoader );
 96  0
         testsToRun = new TestsToRun( locatedClasses );
 97  0
         return testsToRun.getTestSets();
 98  
     }
 99  
 
 100  
     public int getNumTests()
 101  
     {
 102  0
         if ( testsToRun == null )
 103  
         {
 104  0
             throw new IllegalStateException( "You must call locateTestSets before calling getNumTests" );
 105  
         }
 106  0
         return testsToRun.size();
 107  
     }
 108  
 }