View Javadoc
1   package org.apache.maven.surefire.util.internal;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.surefire.util.internal.ImmutableMap.Node;
23  import org.junit.Before;
24  import org.junit.Test;
25  
26  import java.util.HashMap;
27  import java.util.Map;
28  import java.util.Map.Entry;
29  import java.util.Set;
30  
31  import static org.hamcrest.Matchers.hasItem;
32  import static org.hamcrest.Matchers.hasSize;
33  import static org.hamcrest.Matchers.is;
34  import static org.junit.Assert.assertThat;
35  
36  /**
37   * @since 2.20
38   */
39  public class ImmutableMapTest
40  {
41      private ImmutableMap<String, String> map;
42  
43      @Before
44      public void setUp() throws Exception
45      {
46          Map<String, String> backingMap = new HashMap<String, String>();
47          backingMap.put( "a", "1" );
48          backingMap.put( "x", null );
49          backingMap.put( "b", "2" );
50          backingMap.put( "c", "3" );
51          backingMap.put( "", "" );
52          backingMap.put( null, "1" );
53          map = new ImmutableMap<String, String>( backingMap );
54      }
55  
56      @Test
57      public void testEntrySet() throws Exception
58      {
59          Set<Entry<String, String>> entries = map.entrySet();
60          assertThat( entries, hasSize( 6 ) );
61          assertThat( entries, hasItem( new Node<String, String>( "a", "1" ) ) );
62          assertThat( entries, hasItem( new Node<String, String>( "x", null ) ) );
63          assertThat( entries, hasItem( new Node<String, String>( "b", "2" ) ) );
64          assertThat( entries, hasItem( new Node<String, String>( "c", "3" ) ) );
65          assertThat( entries, hasItem( new Node<String, String>( "", "" ) ) );
66          assertThat( entries, hasItem( new Node<String, String>( null, "1" ) ) );
67      }
68  
69      @Test
70      public void testGetter()
71      {
72          assertThat( map.size(), is( 6 ) );
73          assertThat( map.get( "a" ), is( "1" ) );
74          assertThat( map.get( "x" ), is( (String) null ) );
75          assertThat( map.get( "b" ), is( "2" ) );
76          assertThat( map.get( "c" ), is( "3" ) );
77          assertThat( map.get( "" ), is( "" ) );
78          assertThat( map.get( null ), is( "1" ) );
79      }
80  
81      @Test( expected = UnsupportedOperationException.class )
82      public void shouldNotModifyEntries()
83      {
84          map.entrySet().clear();
85      }
86  }