View Javadoc
1   package org.apache.maven.surefire.testset;
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.io.File;
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  /**
27   * Information about the requested test.
28   *
29   * @author Kristian Rosenvold
30   */
31  public class TestRequest
32  {
33      private final List<File> suiteXmlFiles;
34  
35      private final File testSourceDirectory;
36  
37      private final String requestedTest;
38  
39      private final int rerunFailingTestsCount;
40  
41      /**
42       * @since 2.7.3
43       */
44      private final String requestedTestMethod;
45  
46      public TestRequest( List suiteXmlFiles, File testSourceDirectory, String requestedTest )
47      {
48          this( suiteXmlFiles, testSourceDirectory, requestedTest, null );
49      }
50  
51      /**
52       * @since 2.7.3
53       */
54      public TestRequest( List suiteXmlFiles, File testSourceDirectory, String requestedTest, String requestedTestMethod )
55      {
56          this( createFiles( suiteXmlFiles ), testSourceDirectory, requestedTest, requestedTestMethod, 0 );
57      }
58  
59      public TestRequest( List suiteXmlFiles, File testSourceDirectory, String requestedTest, String requestedTestMethod,
60                          int rerunFailingTestsCount )
61      {
62          this.suiteXmlFiles = createFiles( suiteXmlFiles );
63          this.testSourceDirectory = testSourceDirectory;
64          this.requestedTest = requestedTest;
65          this.requestedTestMethod = requestedTestMethod;
66          this.rerunFailingTestsCount = rerunFailingTestsCount;
67      }
68  
69      /**
70       * Represents suitexmlfiles that define the test-run request
71       *
72       * @return A list of java.io.File objects.
73       */
74      public List<File> getSuiteXmlFiles()
75      {
76          return suiteXmlFiles;
77      }
78  
79      /**
80       * Test source directory, normally ${project.build.testSourceDirectory}
81       *
82       * @return A file pointing to test sources
83       */
84      public File getTestSourceDirectory()
85      {
86          return testSourceDirectory;
87      }
88  
89      /**
90       * A specific test request issued with -Dtest= from the command line.
91       *
92       * @return The string specified at the command line
93       */
94      public String getRequestedTest()
95      {
96          return requestedTest;
97      }
98  
99      /**
100      * A specific test request method issued with -Dtest=class#method from the command line.
101      *
102      * @return The string specified at the command line
103      * @since 2.7.3
104      */
105     public String getRequestedTestMethod()
106     {
107         return requestedTestMethod;
108     }
109 
110     /**
111      * How many times to rerun failing tests, issued with -Dsurefire.rerunFailingTestsCount from the command line.
112      *
113      * @return The int parameter to indicate how many times to rerun failing tests
114      */
115     public int getRerunFailingTestsCount()
116     {
117         return this.rerunFailingTestsCount;
118     }
119 
120     private static List<File> createFiles( List suiteXmlFiles )
121     {
122         if ( suiteXmlFiles != null )
123         {
124             List<File> files = new ArrayList<File>();
125             Object element;
126             for ( Object suiteXmlFile : suiteXmlFiles )
127             {
128                 element = suiteXmlFile;
129                 files.add( element instanceof String ? new File( (String) element ) : (File) element );
130             }
131             return files;
132         }
133         return null;
134     }
135 
136 }