You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ListGenerator.java 2.3KB

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