1 package org.apache.maven.plugin.surefire;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import java.util.Enumeration;
22 import java.util.Iterator;
23 import java.util.Properties;
24 import java.util.SortedSet;
25 import java.util.TreeSet;
26
27 import junit.framework.TestCase;
28 import org.apache.maven.surefire.booter.KeyValueSource;
29
30 import static java.util.Collections.list;
31
32
33
34
35 public class SurefirePropertiesTest
36 extends TestCase
37 {
38
39 public void testKeys()
40 throws Exception
41 {
42 SurefireProperties orderedProperties = new SurefireProperties( (KeyValueSource) null );
43 orderedProperties.setProperty( "abc", "1" );
44 orderedProperties.setProperty( "xyz", "1" );
45 orderedProperties.setProperty( "efg", "1" );
46
47 Enumeration<Object> keys = orderedProperties.keys();
48 assertEquals( "abc", keys.nextElement() );
49 assertEquals( "xyz", keys.nextElement() );
50 assertEquals( "efg", keys.nextElement() );
51 }
52
53 public void testKeysReinsert()
54 throws Exception
55 {
56 SurefireProperties orderedProperties = new SurefireProperties( (KeyValueSource) null );
57 orderedProperties.setProperty( "abc", "1" );
58 orderedProperties.setProperty( "xyz", "1" );
59 orderedProperties.setProperty( "efg", "1" );
60 orderedProperties.setProperty( "abc", "2" );
61 orderedProperties.remove( "xyz" );
62 orderedProperties.setProperty( "xyz", "1" );
63
64 Enumeration<Object> keys = orderedProperties.keys();
65 assertEquals( "abc", keys.nextElement() );
66 assertEquals( "efg", keys.nextElement() );
67 assertEquals( "xyz", keys.nextElement() );
68 }
69
70 public void testConstructWithOther()
71 {
72 Properties src = new Properties();
73 src.setProperty( "a", "1" );
74 src.setProperty( "b", "2" );
75 SurefireProperties orderedProperties = new SurefireProperties( src );
76
77
78
79
80 assertEquals( src.size(), list( orderedProperties.keys() ).size() );
81 assertEquals( src.size(), size( orderedProperties.getStringKeySet().iterator() ) );
82 assertEquals( 2, orderedProperties.size() );
83
84 assertTrue( list( orderedProperties.keys() ).contains( "a" ) );
85 assertTrue( list( orderedProperties.keys() ).contains( "b" ) );
86
87 Iterator it = orderedProperties.getStringKeySet().iterator();
88 SortedSet<Object> keys = new TreeSet<Object>();
89 keys.add( it.next() );
90 keys.add( it.next() );
91 it = keys.iterator();
92 assertEquals( "a", it.next() );
93 assertEquals( "b", it.next() );
94 }
95
96 public void testPutAll()
97 {
98 Properties src = new Properties();
99 src.setProperty( "a", "1" );
100 src.setProperty( "b", "2" );
101 SurefireProperties orderedProperties = new SurefireProperties();
102 orderedProperties.putAll( src );
103
104
105
106
107 assertEquals( src.size(), list( orderedProperties.keys() ).size() );
108 assertEquals( src.size(), size( orderedProperties.getStringKeySet().iterator() ) );
109 assertEquals( 2, orderedProperties.size() );
110
111 assertTrue( list( orderedProperties.keys() ).contains( "a" ) );
112 assertTrue( list( orderedProperties.keys() ).contains( "b" ) );
113
114 Iterator it = orderedProperties.getStringKeySet().iterator();
115 SortedSet<Object> keys = new TreeSet<Object>();
116 keys.add( it.next() );
117 keys.add( it.next() );
118 it = keys.iterator();
119 assertEquals( "a", it.next() );
120 assertEquals( "b", it.next() );
121 }
122
123 private static int size( Iterator<?> iterator )
124 {
125 int count = 0;
126 while ( iterator.hasNext() ) {
127 iterator.next();
128 count++;
129 }
130 return count;
131 }
132
133 }