This project has retired. For details please refer to its Attic page.
ListGenerator xref
View Javadoc
1   package org.apache.archiva.test.utils;
2   
3   /*
4    * Copyright 2012 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import org.junit.runners.model.FrameworkMethod;
20  
21  import java.util.ArrayList;
22  import java.util.Collections;
23  import java.util.List;
24  
25  /**
26   * Generator of list of random test method
27   * -Dorg.apache.archiva.test=n
28   * n<=0 default jdk behavior
29   * n>0 number of round of random collection
30   *
31   * @author Eric
32   */
33  public class ListGenerator
34  {
35      private static int MAXROUND = 10;
36  
37      private ListGenerator()
38      {
39      }
40  
41      static List<FrameworkMethod> getShuffleList( List<FrameworkMethod> computeTestMethods )
42      {
43          int testRound;
44          try
45          {
46              testRound = Integer.valueOf( System.getProperty( "org.apache.archiva.test", "0" ) );
47          }
48          catch ( NumberFormatException nfe )
49          {
50              testRound = 0;
51          }
52          if ( testRound <= 0 ) // default list usage
53          {
54              return computeTestMethods;
55          }
56          if ( computeTestMethods == null )
57          {
58              return null;
59          }
60  
61          List<FrameworkMethod> generated = new ArrayList<>();
62  
63          testRound = Math.min( MAXROUND, testRound );
64  
65          for ( int i = 0; i < testRound; i++ )
66          {
67              Collections.shuffle( computeTestMethods );
68              generated.addAll( computeTestMethods );
69          }
70          // Collections.sort( generated, new FrameworkMethodComparator() );
71  
72          return generated;
73      }
74  
75      /*private static class FrameworkMethodComparator
76          implements Comparator<FrameworkMethod>
77      {
78          public int compare( FrameworkMethod frameworkMethod, FrameworkMethod frameworkMethod1 )
79          {
80              return frameworkMethod.getName().compareTo( frameworkMethod1.getName() );
81          }
82      }*/
83  
84  }