1 package org.apache.maven.surefire.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Iterator;
23 import java.util.LinkedHashSet;
24 import java.util.Set;
25
26 import junit.framework.TestCase;
27
28
29
30
31
32 public class TestsToRunTest
33 extends TestCase
34 {
35 public void testGetTestSets()
36 throws Exception
37 {
38 Set<Class<?>> classes = new LinkedHashSet<Class<?>>();
39 classes.add( T1.class );
40 classes.add( T2.class );
41 TestsToRun testsToRun = new TestsToRun( classes );
42 Iterator<Class<?>> it = testsToRun.iterator();
43 assertTrue( it.hasNext() );
44 assertEquals( it.next(), T1.class );
45 assertTrue( it.hasNext() );
46 assertEquals( it.next(), T2.class );
47 assertFalse( it.hasNext() );
48 }
49
50 public void testContainsAtLeast()
51 {
52 Set<Class<?>> classes = new LinkedHashSet<Class<?>>();
53 classes.add( T1.class );
54 classes.add( T2.class );
55 TestsToRun testsToRun = new TestsToRun( classes );
56 assertTrue( testsToRun.containsAtLeast( 2 ) );
57 assertFalse( testsToRun.containsAtLeast( 3 ) );
58 }
59
60 public void testContainsExactly()
61 {
62 Set<Class<?>> classes = new LinkedHashSet<Class<?>>();
63 classes.add( T1.class );
64 classes.add( T2.class );
65 TestsToRun testsToRun = new TestsToRun( classes );
66 assertFalse( testsToRun.containsExactly( 1 ) );
67 assertTrue( testsToRun.containsExactly( 2 ) );
68 assertFalse( testsToRun.containsExactly( 3 ) );
69 }
70
71 public void testToRunArray()
72 {
73 Set<Class<?>> classes = new LinkedHashSet<Class<?>>();
74 classes.add( T1.class );
75 classes.add( T2.class );
76 TestsToRun testsToRun = new TestsToRun( classes );
77 Class<?>[] locatedClasses = testsToRun.getLocatedClasses();
78 assertEquals( 2, locatedClasses.length );
79 }
80
81 public void testGetClassByName()
82 {
83 Set<Class<?>> classes = new LinkedHashSet<Class<?>>();
84 classes.add( T1.class );
85 classes.add( T2.class );
86 TestsToRun testsToRun = new TestsToRun( classes );
87 assertEquals( T1.class, testsToRun.getClassByName( "org.apache.maven.surefire.util.TestsToRunTest$T1" ) );
88 assertEquals( T2.class, testsToRun.getClassByName( "org.apache.maven.surefire.util.TestsToRunTest$T2" ) );
89 assertEquals( null, testsToRun.getClassByName( "org.apache.maven.surefire.util.TestsToRunTest$T3" ) );
90 }
91
92 public void testTwoIterators()
93 {
94 Set<Class<?>> classes = new LinkedHashSet<Class<?>>();
95 classes.add( T1.class );
96 classes.add( T2.class );
97 TestsToRun testsToRun = new TestsToRun( classes );
98
99 Iterator<Class<?>> it1 = testsToRun.iterator();
100
101 assertEquals( it1.next(), T1.class );
102 assertTrue( it1.hasNext() );
103
104 Iterator<Class<?>> it2 = testsToRun.iterated();
105
106 assertEquals( it1.next(), T2.class );
107 assertFalse( it1.hasNext() );
108
109 assertEquals( it2.next(), T1.class );
110 assertFalse( it1.hasNext() );
111 }
112
113 class T1
114 {
115
116 }
117
118 class T2
119 {
120
121 }
122 }
123