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