Coverage Report - org.apache.maven.surefire.util.DefaultScanResult
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultScanResult
38%
15/39
25%
4/16
2,2
 
 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.ArrayList;
 23  
 import java.util.Collections;
 24  
 import java.util.List;
 25  
 import java.util.Properties;
 26  
 
 27  
 /**
 28  
  * @author Kristian Rosenvold
 29  
  */
 30  
 public class DefaultScanResult
 31  
     implements ScanResult
 32  
 {
 33  
     private final List files;
 34  
 
 35  
     private static final String scanResultNo = "tc.";
 36  
 
 37  
     public DefaultScanResult( List files )
 38  2
     {
 39  2
         this.files = files;
 40  2
     }
 41  
 
 42  
     public int size()
 43  
     {
 44  0
         return files.size();
 45  
     }
 46  
 
 47  
     public String getClassName( int index )
 48  
     {
 49  0
         return (String) files.get( index );
 50  
     }
 51  
 
 52  
     public void writeTo( Properties properties )
 53  
     {
 54  1
         int size = files.size();
 55  3
         for ( int i = 0; i < size; i++ )
 56  
         {
 57  2
             properties.setProperty( scanResultNo + i, (String) files.get( i ) );
 58  
         }
 59  1
     }
 60  
 
 61  
     public static DefaultScanResult from( Properties properties )
 62  
     {
 63  1
         List result = new ArrayList();
 64  1
         int i = 0;
 65  
         while ( true )
 66  
         {
 67  3
             String item = properties.getProperty( scanResultNo + ( i++ ) );
 68  3
             if ( item == null )
 69  
             {
 70  1
                 return new DefaultScanResult( result );
 71  
             }
 72  2
             result.add( item );
 73  2
         }
 74  
     }
 75  
 
 76  
     public boolean isEmpty()
 77  
     {
 78  0
         return files.isEmpty();
 79  
     }
 80  
 
 81  
     public List getFiles()
 82  
     {
 83  1
         return Collections.unmodifiableList( files );
 84  
     }
 85  
 
 86  
     public TestsToRun applyFilter( ScannerFilter scannerFilter, ClassLoader testClassLoader )
 87  
     {
 88  0
         List result = new ArrayList();
 89  
 
 90  0
         int size = size();
 91  0
         for ( int i = 0; i < size; i++ )
 92  
         {
 93  0
             String className = getClassName( i );
 94  
 
 95  0
             Class testClass = loadClass( testClassLoader, className );
 96  
 
 97  0
             if ( scannerFilter == null || scannerFilter.accept( testClass ) )
 98  
             {
 99  0
                 result.add( testClass );
 100  
             }
 101  
         }
 102  
 
 103  0
         return new TestsToRun( result );
 104  
     }
 105  
 
 106  
     public List getClassesSkippedByValidation( ScannerFilter scannerFilter, ClassLoader testClassLoader )
 107  
     {
 108  0
         List result = new ArrayList();
 109  
 
 110  0
         int size = size();
 111  0
         for ( int i = 0; i < size; i++ )
 112  
         {
 113  0
             String className = getClassName( i );
 114  
 
 115  0
             Class testClass = loadClass( testClassLoader, className );
 116  
 
 117  0
             if ( scannerFilter != null && !scannerFilter.accept( testClass ) )
 118  
             {
 119  0
                 result.add( testClass );
 120  
             }
 121  
         }
 122  
 
 123  0
         return result;
 124  
     }
 125  
 
 126  
     private static Class loadClass( ClassLoader classLoader, String className )
 127  
     {
 128  
         Class testClass;
 129  
         try
 130  
         {
 131  0
             testClass = classLoader.loadClass( className );
 132  
         }
 133  0
         catch ( ClassNotFoundException e )
 134  
         {
 135  0
             throw new NestedRuntimeException( "Unable to create test class '" + className + "'", e );
 136  0
         }
 137  0
         return testClass;
 138  
     }
 139  
 
 140  
 
 141  
 }