View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.surefire.api.util;
20  
21  import java.util.Iterator;
22  import java.util.LinkedHashSet;
23  import java.util.Set;
24  
25  import junit.framework.TestCase;
26  
27  /**
28   * @author Kristian Rosenvold
29   */
30  public class TestsToRunTest extends TestCase {
31      public void testGetTestSets() {
32          Set<Class<?>> classes = new LinkedHashSet<>();
33          classes.add(T1.class);
34          classes.add(T2.class);
35          TestsToRun testsToRun = new TestsToRun(classes);
36          Iterator<Class<?>> it = testsToRun.iterator();
37          assertTrue(it.hasNext());
38          assertEquals(it.next(), T1.class);
39          assertTrue(it.hasNext());
40          assertEquals(it.next(), T2.class);
41          assertFalse(it.hasNext());
42      }
43  
44      public void testContainsAtLeast() {
45          Set<Class<?>> classes = new LinkedHashSet<>();
46          classes.add(T1.class);
47          classes.add(T2.class);
48          TestsToRun testsToRun = new TestsToRun(classes);
49          assertTrue(testsToRun.containsAtLeast(2));
50          assertFalse(testsToRun.containsAtLeast(3));
51      }
52  
53      public void testContainsExactly() {
54          Set<Class<?>> classes = new LinkedHashSet<>();
55          classes.add(T1.class);
56          classes.add(T2.class);
57          TestsToRun testsToRun = new TestsToRun(classes);
58          assertFalse(testsToRun.containsExactly(1));
59          assertTrue(testsToRun.containsExactly(2));
60          assertFalse(testsToRun.containsExactly(3));
61      }
62  
63      public void testToRunArray() {
64          Set<Class<?>> classes = new LinkedHashSet<>();
65          classes.add(T1.class);
66          classes.add(T2.class);
67          TestsToRun testsToRun = new TestsToRun(classes);
68          Class<?>[] locatedClasses = testsToRun.getLocatedClasses();
69          assertEquals(2, locatedClasses.length);
70      }
71  
72      public void testGetClassByName() {
73          Set<Class<?>> classes = new LinkedHashSet<>();
74          classes.add(T1.class);
75          classes.add(T2.class);
76          TestsToRun testsToRun = new TestsToRun(classes);
77          assertEquals(T1.class, testsToRun.getClassByName("org.apache.maven.surefire.api.util.TestsToRunTest$T1"));
78          assertEquals(T2.class, testsToRun.getClassByName("org.apache.maven.surefire.api.util.TestsToRunTest$T2"));
79          assertNull(testsToRun.getClassByName("org.apache.maven.surefire.util.TestsToRunTest$T3"));
80      }
81  
82      public void testTwoIterators() {
83          Set<Class<?>> classes = new LinkedHashSet<>();
84          classes.add(T1.class);
85          classes.add(T2.class);
86          TestsToRun testsToRun = new TestsToRun(classes);
87  
88          Iterator<Class<?>> it1 = testsToRun.iterator();
89  
90          assertEquals(it1.next(), T1.class);
91          assertTrue(it1.hasNext());
92  
93          Iterator<Class<?>> it2 = testsToRun.iterated();
94  
95          assertEquals(it1.next(), T2.class);
96          assertFalse(it1.hasNext());
97  
98          assertEquals(it2.next(), T1.class);
99          assertFalse(it1.hasNext());
100     }
101 
102     static class T1 {}
103 
104     static class T2 {}
105 }