001package org.apache.archiva.test.utils; 002 003/* 004 * Copyright 2012 The Apache Software Foundation. 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019import org.junit.runners.model.FrameworkMethod; 020 021import java.util.ArrayList; 022import java.util.Collections; 023import java.util.List; 024 025/** 026 * Generator of list of random test method 027 * -Dorg.apache.archiva.test=n 028 * n<=0 default jdk behavior 029 * n>0 number of round of random collection 030 * 031 * @author Eric 032 */ 033public class ListGenerator 034{ 035 private static int MAXROUND = 10; 036 037 private ListGenerator() 038 { 039 } 040 041 static List<FrameworkMethod> getShuffleList( List<FrameworkMethod> computeTestMethods ) 042 { 043 int testRound; 044 try 045 { 046 testRound = Integer.valueOf( System.getProperty( "org.apache.archiva.test", "0" ) ); 047 } 048 catch ( NumberFormatException nfe ) 049 { 050 testRound = 0; 051 } 052 if ( testRound <= 0 ) // default list usage 053 { 054 return computeTestMethods; 055 } 056 if ( computeTestMethods == null ) 057 { 058 return null; 059 } 060 061 List<FrameworkMethod> generated = new ArrayList<>(); 062 063 testRound = Math.min( MAXROUND, testRound ); 064 065 for ( int i = 0; i < testRound; i++ ) 066 { 067 Collections.shuffle( computeTestMethods ); 068 generated.addAll( computeTestMethods ); 069 } 070 // Collections.sort( generated, new FrameworkMethodComparator() ); 071 072 return generated; 073 } 074 075 /*private static class FrameworkMethodComparator 076 implements Comparator<FrameworkMethod> 077 { 078 public int compare( FrameworkMethod frameworkMethod, FrameworkMethod frameworkMethod1 ) 079 { 080 return frameworkMethod.getName().compareTo( frameworkMethod1.getName() ); 081 } 082 }*/ 083 084}