Coverage Report - org.apache.maven.surefire.suite.AbstractDirectoryTestSuite
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractDirectoryTestSuite
0%
0/45
0%
0/18
3.143
 
 1  
 package org.apache.maven.surefire.suite;
 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.Surefire;
 23  
 import org.apache.maven.surefire.report.ReporterManagerFactory;
 24  
 import org.apache.maven.surefire.util.SurefireDirectoryScanner;
 25  
 import org.apache.maven.surefire.report.ReportEntry;
 26  
 import org.apache.maven.surefire.report.ReporterException;
 27  
 import org.apache.maven.surefire.report.ReporterManager;
 28  
 import org.apache.maven.surefire.testset.SurefireTestSet;
 29  
 import org.apache.maven.surefire.testset.TestSetFailedException;
 30  
 
 31  
 import java.io.File;
 32  
 import java.util.Collections;
 33  
 import java.util.HashMap;
 34  
 import java.util.Iterator;
 35  
 import java.util.List;
 36  
 import java.util.Map;
 37  
 import java.util.ResourceBundle;
 38  
 
 39  
 public abstract class AbstractDirectoryTestSuite
 40  
     implements SurefireTestSuite
 41  
 {
 42  0
     protected static ResourceBundle bundle = ResourceBundle.getBundle( Surefire.SUREFIRE_BUNDLE_NAME );
 43  
 
 44  
     protected Map testSets;
 45  
 
 46  
     private int totalTests;
 47  
     
 48  
     private final SurefireDirectoryScanner surefireDirectoryScanner;
 49  
 
 50  
 
 51  
     protected AbstractDirectoryTestSuite( File basedir, List includes, List excludes )
 52  0
     {
 53  0
         this.surefireDirectoryScanner = new SurefireDirectoryScanner(basedir, includes, excludes);
 54  0
     }
 55  
 
 56  
     public Map locateTestSets( ClassLoader classLoader )
 57  
         throws TestSetFailedException
 58  
     {
 59  0
         if ( testSets != null )
 60  
         {
 61  0
             throw new IllegalStateException( "You can't call locateTestSets twice" );
 62  
         }
 63  0
         testSets = new HashMap();
 64  
 
 65  0
         Class[] locatedClasses = surefireDirectoryScanner.locateTestClasses( classLoader);
 66  
 
 67  0
         for ( int i = 0; i < locatedClasses.length; i++ )
 68  
         {
 69  0
             Class testClass = locatedClasses[i];
 70  0
             SurefireTestSet testSet = createTestSet( testClass, classLoader );
 71  
 
 72  0
                 if ( testSet == null )
 73  
                 {
 74  0
                     continue;
 75  
                 }
 76  
 
 77  0
                 if ( testSets.containsKey( testSet.getName() ) )
 78  
                 {
 79  0
                     throw new TestSetFailedException( "Duplicate test set '" + testSet.getName() + "'" );
 80  
                 }
 81  0
                 testSets.put( testSet.getName(), testSet );
 82  
 
 83  0
                 totalTests++;
 84  
         }
 85  
 
 86  0
         return Collections.unmodifiableMap( testSets );
 87  
     }
 88  
 
 89  
     protected abstract SurefireTestSet createTestSet( Class testClass, ClassLoader classLoader )
 90  
         throws TestSetFailedException;
 91  
 
 92  
     public void execute( ReporterManagerFactory reporterManagerFactory, ClassLoader classLoader )
 93  
         throws ReporterException, TestSetFailedException
 94  
     {
 95  0
         if ( testSets == null )
 96  
         {
 97  0
             throw new IllegalStateException( "You must call locateTestSets before calling execute" );
 98  
         }
 99  0
         for ( Iterator i = testSets.values().iterator(); i.hasNext(); )
 100  
         {
 101  0
             SurefireTestSet testSet = (SurefireTestSet) i.next();
 102  
 
 103  0
             executeTestSet( testSet, reporterManagerFactory, classLoader );
 104  0
         }
 105  0
     }
 106  
 
 107  
     private void executeTestSet( SurefireTestSet testSet, ReporterManagerFactory reporterManagerFactory,
 108  
                                  ClassLoader classLoader )
 109  
         throws ReporterException, TestSetFailedException
 110  
     {
 111  
 
 112  0
         ReporterManager reporterManager = reporterManagerFactory.createReporterManager();
 113  
 
 114  0
         String rawString = bundle.getString( "testSetStarting" );
 115  
 
 116  0
         ReportEntry report = new ReportEntry( this.getClass().getName(), testSet.getName(), rawString );
 117  
 
 118  0
         reporterManager.testSetStarting( report );
 119  
 
 120  0
         testSet.execute( reporterManager, classLoader );
 121  
 
 122  0
         rawString = bundle.getString( "testSetCompletedNormally" );
 123  
 
 124  0
         report = new ReportEntry( this.getClass().getName(), testSet.getName(), rawString );
 125  
 
 126  0
         reporterManager.testSetCompleted( report );
 127  
 
 128  0
         reporterManager.reset();
 129  0
     }
 130  
 
 131  
     public void execute( String testSetName, ReporterManagerFactory reporterManagerFactory, ClassLoader classLoader )
 132  
         throws ReporterException, TestSetFailedException
 133  
     {
 134  0
         if ( testSets == null )
 135  
         {
 136  0
             throw new IllegalStateException( "You must call locateTestSets before calling execute" );
 137  
         }
 138  0
         SurefireTestSet testSet = (SurefireTestSet) testSets.get( testSetName );
 139  
 
 140  0
         if ( testSet == null )
 141  
         {
 142  0
             throw new TestSetFailedException( "Unable to find test set '" + testSetName + "' in suite" );
 143  
         }
 144  
 
 145  0
         executeTestSet( testSet, reporterManagerFactory, classLoader );
 146  0
     }
 147  
 
 148  
     public int getNumTests()
 149  
     {
 150  0
         if ( testSets == null )
 151  
         {
 152  0
             throw new IllegalStateException( "You must call locateTestSets before calling getNumTests" );
 153  
         }
 154  0
         return totalTests;
 155  
     }
 156  
 
 157  
 }