1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections4.map;
18
19 import static org.junit.jupiter.api.Assertions.assertSame;
20 import static org.junit.jupiter.api.Assertions.assertThrows;
21 import static org.junit.jupiter.api.Assertions.assertTrue;
22
23 import java.util.SortedMap;
24 import java.util.TreeMap;
25
26 import org.apache.commons.collections4.Unmodifiable;
27 import org.junit.jupiter.api.Test;
28
29
30
31
32
33 public class UnmodifiableSortedMapTest<K, V> extends AbstractSortedMapTest<K, V> {
34
35 public UnmodifiableSortedMapTest() {
36 super(UnmodifiableSortedMapTest.class.getSimpleName());
37 }
38
39 @Override
40 public String getCompatibilityVersion() {
41 return "4";
42 }
43
44 @Override
45 public boolean isPutAddSupported() {
46 return false;
47 }
48
49 @Override
50 public boolean isPutChangeSupported() {
51 return false;
52 }
53
54 @Override
55 public boolean isRemoveSupported() {
56 return false;
57 }
58
59 @Override
60 public SortedMap<K, V> makeFullMap() {
61 final SortedMap<K, V> m = new TreeMap<>();
62 addSampleMappings(m);
63 return UnmodifiableSortedMap.unmodifiableSortedMap(m);
64 }
65
66 @Override
67 public SortedMap<K, V> makeObject() {
68 return UnmodifiableSortedMap.unmodifiableSortedMap(new TreeMap<>());
69 }
70
71 @Test
72 public void testDecorateFactory() {
73 final SortedMap<K, V> map = makeFullMap();
74 assertSame(map, UnmodifiableSortedMap.unmodifiableSortedMap(map));
75
76 assertThrows(NullPointerException.class, () -> UnmodifiableSortedMap.unmodifiableSortedMap(null));
77 }
78
79 @Test
80 public void testHeadMap() {
81 final SortedMap<K, V> map = makeFullMap();
82 final SortedMap<K, V> m = new TreeMap<>();
83
84 assertSame(m.isEmpty(), map.headMap((K) "again").isEmpty());
85 assertSame(18, map.size());
86
87 assertSame(17, map.headMap((K) "you").size());
88
89 assertSame(16, map.headMap((K) "we'll").size());
90 }
91
92 @Test
93 public void testSubMap() {
94 final SortedMap<K, V> map = makeFullMap();
95
96 assertSame(18, map.size());
97
98 assertSame(17, map.subMap((K) "again", (K) "you").size());
99
100 assertSame(16, map.subMap((K) "again", (K) "we'll").size());
101
102 assertSame(0, map.subMap((K) "again", (K) "again").size());
103
104 assertSame(map.headMap((K) "you").size(), map.subMap((K) "again", (K) "you").size());
105 }
106
107 @Test
108 public void testTailMap() {
109 final SortedMap<K, V> map = makeFullMap();
110
111 assertSame(18, map.size());
112
113 assertSame(1, map.tailMap((K) "you").size());
114
115 assertSame(2, map.tailMap((K) "we'll").size());
116
117 assertSame(18, map.tailMap((K) "again").size());
118 }
119
120 @Test
121 public void testUnmodifiable() {
122 assertTrue(makeObject() instanceof Unmodifiable);
123 assertTrue(makeFullMap() instanceof Unmodifiable);
124 }
125
126
127
128
129
130
131
132
133
134
135
136
137 }