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 /**
40 * @since 2.7.3
41 */
42 private final String requestedTestMethod;
43
44 public TestRequest( List suiteXmlFiles, File testSourceDirectory, String requestedTest )
45 {
46 this( suiteXmlFiles, testSourceDirectory, requestedTest, null );
47 }
48
49 /**
50 * @since 2.7.3
51 */
52 public TestRequest( List suiteXmlFiles, File testSourceDirectory, String requestedTest, String requestedTestMethod )
53 {
54 this.suiteXmlFiles = createFiles( suiteXmlFiles );
55 this.testSourceDirectory = testSourceDirectory;
56 this.requestedTest = requestedTest;
57 this.requestedTestMethod = requestedTestMethod;
58 }
59
60 /**
61 * Represents suitexmlfiles that define the test-run request
62 *
63 * @return A list of java.io.File objects.
64 */
65 public List<File> getSuiteXmlFiles()
66 {
67 return suiteXmlFiles;
68 }
69
70 /**
71 * Test source directory, normally ${project.build.testSourceDirectory}
72 *
73 * @return A file pointing to test sources
74 */
75 public File getTestSourceDirectory()
76 {
77 return testSourceDirectory;
78 }
79
80 /**
81 * A specific test request issued with -Dtest= from the command line.
82 *
83 * @return The string specified at the command line
84 */
85 public String getRequestedTest()
86 {
87 return requestedTest;
88 }
89
90 /**
91 * A specific test request method issued with -Dtest=class#method from the command line.
92 *
93 * @return The string specified at the command line
94 * @since 2.7.3
95 */
96 public String getRequestedTestMethod()
97 {
98 return requestedTestMethod;
99 }
100
101 private static List<File> createFiles( List suiteXmlFiles )
102 {
103 if ( suiteXmlFiles != null )
104 {
105 List<File> files = new ArrayList<File>();
106 Object element;
107 for ( Object suiteXmlFile : suiteXmlFiles )
108 {
109 element = suiteXmlFile;
110 files.add( element instanceof String ? new File( (String) element ) : (File) element );
111 }
112 return files;
113 }
114 return null;
115 }
116
117 }