Coverage Report - org.apache.maven.surefire.util.RunOrder
 
Classes in this File Line Coverage Branch Coverage Complexity
RunOrder
95%
44/46
94%
17/18
2,333
 
 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.List;
 24  
 import java.util.StringTokenizer;
 25  
 
 26  
 /**
 27  
  * A RunOrder specifies the order in which the tests will be run.
 28  
  *
 29  
  * @author Stefan Birkner
 30  
  */
 31  
 public class RunOrder
 32  
 {
 33  1
     public static final RunOrder ALPHABETICAL = new RunOrder( "alphabetical" );
 34  
 
 35  1
     public static final RunOrder FILESYSTEM = new RunOrder( "filesystem" );
 36  
 
 37  1
     public static final RunOrder HOURLY = new RunOrder( "hourly" );
 38  
 
 39  1
     public static final RunOrder RANDOM = new RunOrder( "random" );
 40  
 
 41  1
     public static final RunOrder REVERSE_ALPHABETICAL = new RunOrder( "reversealphabetical" );
 42  
 
 43  1
     public static final RunOrder BALANCED = new RunOrder( "balanced" );
 44  
 
 45  1
     public static final RunOrder FAILEDFIRST = new RunOrder( "failedfirst" );
 46  
 
 47  1
     public static final RunOrder[] DEFAULT = new RunOrder[]{ FILESYSTEM };
 48  
 
 49  
     /**
 50  
      * Returns the specified RunOrder
 51  
      *
 52  
      * @param values The runorder string value
 53  
      * @return An array of RunOrder objects, never null
 54  
      */
 55  
     public static RunOrder[] valueOfMulti( String values )
 56  
     {
 57  5
         List result = new ArrayList();
 58  5
         if ( values != null )
 59  
         {
 60  4
             StringTokenizer stringTokenizer = new StringTokenizer( values, "," );
 61  8
             while ( stringTokenizer.hasMoreTokens() )
 62  
             {
 63  5
                 result.add( valueOf( stringTokenizer.nextToken() ) );
 64  
             }
 65  
         }
 66  4
         return (RunOrder[]) result.toArray( new RunOrder[result.size()] );
 67  
     }
 68  
 
 69  
     public static RunOrder valueOf( String name )
 70  
     {
 71  5
         if ( name == null )
 72  
         {
 73  0
             return null;
 74  
         }
 75  
         else
 76  
         {
 77  5
             RunOrder[] runOrders = values();
 78  27
             for ( int i = 0; i < runOrders.length; i++ )
 79  
             {
 80  26
                 if ( runOrders[i].matches( name ) )
 81  
                 {
 82  4
                     return runOrders[i];
 83  
                 }
 84  
             }
 85  
 
 86  1
             StringBuffer errorMessage = createMessageForMissingRunOrder( name );
 87  1
             throw new IllegalArgumentException( errorMessage.toString() );
 88  
         }
 89  
     }
 90  
 
 91  
     private static StringBuffer createMessageForMissingRunOrder( String name )
 92  
     {
 93  1
         RunOrder[] runOrders = values();
 94  1
         StringBuffer message = new StringBuffer();
 95  1
         message.append( "There's no RunOrder with the name " );
 96  1
         message.append( name );
 97  1
         message.append( ". Please use one of the following RunOrders: " );
 98  8
         for ( int i = 0; i < runOrders.length; i++ )
 99  
         {
 100  7
             if ( i != 0 )
 101  
             {
 102  6
                 message.append( ", " );
 103  
             }
 104  7
             message.append( runOrders[i] );
 105  
         }
 106  1
         message.append( "." );
 107  1
         return message;
 108  
     }
 109  
 
 110  
     private static RunOrder[] values()
 111  
     {
 112  6
         return new RunOrder[]{ ALPHABETICAL, FILESYSTEM, HOURLY, RANDOM, REVERSE_ALPHABETICAL, BALANCED, FAILEDFIRST };
 113  
     }
 114  
 
 115  
     public static String asString( RunOrder[] runOrder )
 116  
     {
 117  1
         StringBuffer stringBuffer = new StringBuffer();
 118  3
         for ( int i = 0; i < runOrder.length; i++ )
 119  
         {
 120  2
             stringBuffer.append( runOrder[i].name );
 121  2
             if ( i < ( runOrder.length - 1 ) )
 122  
             {
 123  1
                 stringBuffer.append( "," );
 124  
             }
 125  
         }
 126  1
         return stringBuffer.toString();
 127  
 
 128  
     }
 129  
 
 130  
     private final String name;
 131  
 
 132  
     private RunOrder( String name )
 133  7
     {
 134  7
         this.name = name;
 135  7
     }
 136  
 
 137  
     private boolean matches( String anotherName )
 138  
     {
 139  26
         return name.equalsIgnoreCase( anotherName );
 140  
     }
 141  
 
 142  
     public String name()
 143  
     {
 144  0
         return name;
 145  
     }
 146  
 
 147  
     public String toString()
 148  
     {
 149  7
         return name;
 150  
     }
 151  
 }