Coverage Report - org.apache.maven.surefire.junitcore.JUnitCoreWrapper
 
Classes in this File Line Coverage Branch Coverage Complexity
JUnitCoreWrapper
0 %
0/23
0 %
0/10
0
 
 1  
 package org.apache.maven.surefire.junitcore;
 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.testset.TestSetFailedException;
 23  
 import org.apache.maven.surefire.util.TestsToRun;
 24  
 
 25  
 import java.util.List;
 26  
 import java.util.concurrent.ExecutionException;
 27  
 
 28  
 import org.junit.runner.Computer;
 29  
 import org.junit.runner.JUnitCore;
 30  
 import org.junit.runner.notification.RunListener;
 31  
 
 32  
 /**
 33  
  * Encapsulates access to JUnitCore
 34  
  *
 35  
  * @author Kristian Rosenvold
 36  
  */
 37  
 
 38  0
 class JUnitCoreWrapper
 39  
 {
 40  
     public static void execute( TestsToRun testsToRun, JUnitCoreParameters jUnitCoreParameters,
 41  
                                 List<RunListener> listeners )
 42  
         throws TestSetFailedException
 43  
     {
 44  0
         Computer computer = getComputer( jUnitCoreParameters );
 45  0
         JUnitCore junitCore = new JUnitCore();
 46  0
         for ( RunListener runListener : listeners )
 47  
         {
 48  0
             junitCore.addListener( runListener );
 49  
         }
 50  
         try
 51  
         {
 52  0
             junitCore.run( computer, testsToRun.getLocatedClasses() );
 53  
         }
 54  
         finally
 55  
         {
 56  0
             closeIfConfigurable( computer );
 57  0
             for ( RunListener runListener : listeners )
 58  
             {
 59  0
                 junitCore.removeListener( runListener );
 60  
             }
 61  0
         }
 62  0
     }
 63  
 
 64  
     private static void closeIfConfigurable( Computer computer )
 65  
         throws TestSetFailedException
 66  
     {
 67  0
         if ( computer instanceof ConfigurableParallelComputer )
 68  
         {
 69  
             try
 70  
             {
 71  0
                 ( (ConfigurableParallelComputer) computer ).close();
 72  
             }
 73  0
             catch ( ExecutionException e )
 74  
             {
 75  0
                 throw new TestSetFailedException( e );
 76  0
             }
 77  
         }
 78  0
     }
 79  
 
 80  
     private static Computer getComputer( JUnitCoreParameters jUnitCoreParameters )
 81  
         throws TestSetFailedException
 82  
     {
 83  0
         if ( jUnitCoreParameters.isNoThreading() )
 84  
         {
 85  0
             return new Computer();
 86  
         }
 87  0
         return getConfigurableParallelComputer( jUnitCoreParameters );
 88  
     }
 89  
 
 90  
     private static Computer getConfigurableParallelComputer( JUnitCoreParameters jUnitCoreParameters )
 91  
         throws TestSetFailedException
 92  
     {
 93  0
         if ( jUnitCoreParameters.isUseUnlimitedThreads() )
 94  
         {
 95  0
             return new ConfigurableParallelComputer();
 96  
         }
 97  
         else
 98  
         {
 99  0
             return new ConfigurableParallelComputer(
 100  
                 jUnitCoreParameters.isParallelClasses() | jUnitCoreParameters.isParallelBoth(),
 101  
                 jUnitCoreParameters.isParallelMethod() | jUnitCoreParameters.isParallelBoth(),
 102  
                 jUnitCoreParameters.getThreadCount(), jUnitCoreParameters.isPerCoreThreadCount() );
 103  
         }
 104  
     }
 105  
 }