1 package org.apache.maven.surefire.util.internal;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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 }