View Javadoc

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  /**
23   * A RunOrder specifies the order in which the tests will be run.
24   * 
25   * @author Stefan Birkner
26   */
27  public class RunOrder
28  {
29      public static final RunOrder ALPHABETICAL = new RunOrder( "alphabetical" );
30  
31      public static final RunOrder FILESYSTEM = new RunOrder( "filesystem" );
32  
33      public static final RunOrder HOURLY = new RunOrder( "hourly" );
34  
35      public static final RunOrder RANDOM = new RunOrder( "random" );
36  
37      public static final RunOrder REVERSE_ALPHABETICAL = new RunOrder( "reversealphabetical" );
38  
39      public static RunOrder valueOf( String name )
40      {
41          if ( name == null )
42          {
43              return null;
44          }
45          else
46          {
47              RunOrder[] runOrders = values();
48              for ( int i = 0; i < runOrders.length; i++ )
49              {
50                  if ( runOrders[i].matches( name ) )
51                  {
52                      return runOrders[i];
53                  }
54              }
55  
56              StringBuffer errorMessage = createMessageForMissingRunOrder( name );
57              throw new IllegalArgumentException( errorMessage.toString() );
58          }
59      }
60  
61      private static StringBuffer createMessageForMissingRunOrder( String name )
62      {
63          RunOrder[] runOrders = values();
64          StringBuffer message = new StringBuffer();
65          message.append( "There's no RunOrder with the name " );
66          message.append( name );
67          message.append( ". Please use one of the following RunOrders: " );
68          for ( int i = 0; i < runOrders.length; i++ )
69          {
70              if ( i != 0 )
71              {
72                  message.append( ", " );
73              }
74              message.append( runOrders[i] );
75          }
76          message.append( "." );
77          return message;
78      }
79  
80      private static RunOrder[] values()
81      {
82          return new RunOrder[] { ALPHABETICAL, FILESYSTEM, HOURLY, RANDOM, REVERSE_ALPHABETICAL };
83      }
84  
85      private final String name;
86  
87      private RunOrder( String name )
88      {
89          this.name = name;
90      }
91  
92      private boolean matches( String anotherName )
93      {
94          return name.equalsIgnoreCase( anotherName );
95      }
96  
97      public String name()
98      {
99          return name;
100     }
101 
102     public String toString()
103     {
104         return name;
105     }
106 }