View Javadoc

1   package org.apache.maven.plugin.surefire;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   */
20  
21  import java.util.Enumeration;
22  import java.util.Properties;
23  
24  import junit.framework.TestCase;
25  import org.apache.maven.surefire.booter.KeyValueSource;
26  
27  /**
28   * Tests the insertion-order preserving properties collection
29   */
30  public class SurefirePropertiesTest
31      extends TestCase
32  {
33  
34      public void testKeys()
35          throws Exception
36      {
37          SurefireProperties orderedProperties = new SurefireProperties( (KeyValueSource) null );
38          orderedProperties.setProperty( "abc", "1" );
39          orderedProperties.setProperty( "xyz", "1" );
40          orderedProperties.setProperty( "efg", "1" );
41  
42          Enumeration<Object> keys = orderedProperties.keys();
43          assertEquals( "abc", keys.nextElement() );
44          assertEquals( "xyz", keys.nextElement() );
45          assertEquals( "efg", keys.nextElement() );
46  
47      }
48  
49      public void testKeysReinsert()
50          throws Exception
51      {
52          SurefireProperties orderedProperties = new SurefireProperties( (KeyValueSource)null );
53          orderedProperties.setProperty( "abc", "1" );
54          orderedProperties.setProperty( "xyz", "1" );
55          orderedProperties.setProperty( "efg", "1" );
56          orderedProperties.setProperty( "abc", "2" );
57          orderedProperties.remove( "xyz" );
58          orderedProperties.setProperty( "xyz", "1" );
59  
60          Enumeration<Object> keys = orderedProperties.keys();
61          assertEquals( "abc", keys.nextElement() );
62          assertEquals( "efg", keys.nextElement() );
63          assertEquals( "xyz", keys.nextElement() );
64      }
65  
66      public void testConstructWithOther()
67      {
68          Properties src = new Properties();
69          src.setProperty( "a", "1" );
70          src.setProperty( "b", "2" );
71          SurefireProperties orderedProperties = new SurefireProperties( src );
72          // Cannot make assumptions about insertion order
73          assertEquals( 2, orderedProperties.size() );
74  
75  
76      }
77  
78  }