Coverage Report - org.apache.maven.surefire.util.TestsToRun
 
Classes in this File Line Coverage Branch Coverage Complexity
TestsToRun
0%
0/23
0%
0/6
1.667
 
 1  
 package org.apache.maven.surefire.util;
 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 java.util.Arrays;
 23  
 import java.util.Collections;
 24  
 import java.util.HashSet;
 25  
 import java.util.Iterator;
 26  
 import java.util.List;
 27  
 import java.util.Set;
 28  
 import org.apache.maven.surefire.testset.TestSetFailedException;
 29  
 
 30  
 /**
 31  
  * Contains all the tests that have been found according to specified include/exclude
 32  
  * specification for a given surefire run.
 33  
  *
 34  
  * @author Kristian Rosenvold (junit core adaption)
 35  
  */
 36  
 public class TestsToRun
 37  
 {
 38  
     private final List locatedClasses;
 39  
 
 40  
     /**
 41  
      * Constructor
 42  
      *
 43  
      * @param locatedClasses A list of java.lang.Class objects representing tests to run
 44  
      */
 45  
     public TestsToRun( List locatedClasses )
 46  0
     {
 47  0
         this.locatedClasses = Collections.unmodifiableList( locatedClasses );
 48  0
         Set testSets = new HashSet();
 49  
 
 50  0
         for ( Iterator iterator = locatedClasses.iterator(); iterator.hasNext(); )
 51  
         {
 52  0
             Class testClass = (Class) iterator.next();
 53  0
             if ( testSets.contains( testClass ) )
 54  
             {
 55  0
                 throw new RuntimeException( "Duplicate test set '" + testClass.getName() + "'" );
 56  
             }
 57  0
             testSets.add( testClass );
 58  0
         }
 59  0
     }
 60  
 
 61  
     public static TestsToRun fromClass( Class clazz )
 62  
         throws TestSetFailedException
 63  
     {
 64  0
         return new TestsToRun( Arrays.asList( new Class[]{ clazz } ) );
 65  
     }
 66  
 
 67  
     public int size()
 68  
     {
 69  0
         return locatedClasses.size();
 70  
     }
 71  
 
 72  
     public Class[] getLocatedClasses()
 73  
     {
 74  0
         return (Class[]) locatedClasses.toArray( new Class[locatedClasses.size()] );
 75  
     }
 76  
 
 77  
     /**
 78  
      * Returns an iterator over the located java.lang.Class objects
 79  
      *
 80  
      * @return an unmodifiable iterator
 81  
      */
 82  
     public Iterator iterator()
 83  
     {
 84  0
         return locatedClasses.iterator();
 85  
     }
 86  
 
 87  
     public String toString()
 88  
     {
 89  0
         StringBuffer sb = new StringBuffer();
 90  0
         sb.append( "TestsToRun: [" );
 91  0
         Iterator it = iterator();
 92  0
         while ( it.hasNext() )
 93  
         {
 94  0
             Class clazz = (Class) it.next();
 95  0
             sb.append( " " ).append( clazz.getName() );
 96  0
         }
 97  
 
 98  0
         sb.append( ']' );
 99  0
         return sb.toString();
 100  
     }
 101  
 
 102  
 }