Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
TestsToRun |
|
| 1.6;1,6 |
1 | package org.apache.maven.surefire.util; | |
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 org.apache.maven.surefire.testset.TestSetFailedException; | |
23 | ||
24 | import java.util.Arrays; | |
25 | import java.util.Collections; | |
26 | import java.util.HashSet; | |
27 | import java.util.Iterator; | |
28 | import java.util.List; | |
29 | import java.util.Set; | |
30 | ||
31 | /** | |
32 | * Contains all the tests that have been found according to specified include/exclude | |
33 | * specification for a given surefire run. | |
34 | * | |
35 | * @author Kristian Rosenvold (junit core adaption) | |
36 | */ | |
37 | public class TestsToRun | |
38 | { | |
39 | private final List locatedClasses; | |
40 | ||
41 | /** | |
42 | * Constructor | |
43 | * | |
44 | * @param locatedClasses A list of java.lang.Class objects representing tests to run | |
45 | */ | |
46 | public TestsToRun( List locatedClasses ) | |
47 | 0 | { |
48 | 0 | this.locatedClasses = Collections.unmodifiableList( locatedClasses ); |
49 | 0 | Set testSets = new HashSet(); |
50 | ||
51 | 0 | for ( Iterator iterator = locatedClasses.iterator(); iterator.hasNext(); ) |
52 | { | |
53 | 0 | Class testClass = (Class) iterator.next(); |
54 | 0 | if ( testSets.contains( testClass ) ) |
55 | { | |
56 | 0 | throw new RuntimeException( "Duplicate test set '" + testClass.getName() + "'" ); |
57 | } | |
58 | 0 | testSets.add( testClass ); |
59 | 0 | } |
60 | 0 | } |
61 | ||
62 | public static TestsToRun fromClass( Class clazz ) | |
63 | throws TestSetFailedException | |
64 | { | |
65 | 0 | return new TestsToRun( Arrays.asList( new Class[]{ clazz } ) ); |
66 | } | |
67 | ||
68 | public int size() | |
69 | { | |
70 | 0 | return locatedClasses.size(); |
71 | } | |
72 | ||
73 | public Class[] getLocatedClasses() | |
74 | { | |
75 | 0 | return (Class[]) locatedClasses.toArray( new Class[locatedClasses.size()] ); |
76 | } | |
77 | ||
78 | /** | |
79 | * Returns an iterator over the located java.lang.Class objects | |
80 | * | |
81 | * @return an unmodifiable iterator | |
82 | */ | |
83 | public Iterator iterator() | |
84 | { | |
85 | 0 | return locatedClasses.iterator(); |
86 | } | |
87 | } |