1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections4;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20 import static org.junit.jupiter.api.Assertions.assertTrue;
21
22 import java.util.TreeMap;
23
24 import org.apache.commons.collections4.map.AbstractMapTest;
25 import org.junit.jupiter.api.Test;
26
27
28
29
30 public abstract class AbstractTreeMapTest<K, V> extends AbstractMapTest<K, V> {
31
32 public AbstractTreeMapTest(final String testName) {
33 super(testName);
34 }
35
36 @Override
37 public boolean isAllowNullKey() {
38 return false;
39 }
40
41
42
43
44 @Override
45 public abstract TreeMap<K, V> makeObject();
46
47 @Test
48 public void testNewMap() {
49 final TreeMap<K, V> map = makeObject();
50 assertTrue(map.isEmpty(), "New map is empty");
51 assertEquals(0, map.size(), "New map has size zero");
52 }
53
54 @Test
55 @SuppressWarnings("unchecked")
56 public void testSearch() {
57 final TreeMap<K, V> map = makeObject();
58 map.put((K) "first", (V) "First Item");
59 map.put((K) "second", (V) "Second Item");
60 assertEquals("First Item", map.get("first"),
61 "Top item is 'Second Item'");
62 assertEquals("Second Item", map.get("second"),
63 "Next Item is 'First Item'");
64 }
65
66 }