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.assertEquals;
20 import static org.junit.jupiter.api.Assertions.assertNull;
21 import static org.junit.jupiter.api.Assertions.assertSame;
22
23 import java.util.HashMap;
24 import java.util.Map;
25
26 import org.apache.commons.collections4.Factory;
27 import org.apache.commons.collections4.FactoryUtils;
28 import org.apache.commons.collections4.Transformer;
29 import org.junit.jupiter.api.Test;
30
31
32
33
34
35
36
37
38 @SuppressWarnings("boxing")
39 public class LazyMapTest<K, V> extends AbstractIterableMapTest<K, V> {
40
41 private static final Factory<Integer> oneFactory = FactoryUtils.constantFactory(1);
42
43 @Override
44 public String getCompatibilityVersion() {
45 return "4";
46 }
47
48 @Override
49 protected boolean isLazyMapTest() {
50 return true;
51 }
52
53 @Override
54 public LazyMap<K, V> makeObject() {
55 return LazyMap.lazyMap(new HashMap<>(), FactoryUtils.<V>nullFactory());
56 }
57
58 @Test
59 @Override
60 public void testMapGet() {
61
62 }
63
64 @Test
65 public void testMapGetWithFactory() {
66 Map<Integer, Number> map = LazyMap.lazyMap(new HashMap<>(), oneFactory);
67 assertEquals(0, map.size());
68 final Number i1 = map.get("Five");
69 assertEquals(1, i1);
70 assertEquals(1, map.size());
71 final Number i2 = map.get(new String(new char[] {'F', 'i', 'v', 'e'}));
72 assertEquals(1, i2);
73 assertEquals(1, map.size());
74 assertSame(i1, i2);
75
76 map = LazyMap.lazyMap(new HashMap<>(), FactoryUtils.<Long>nullFactory());
77 final Object o = map.get("Five");
78 assertNull(o);
79 assertEquals(1, map.size());
80 }
81
82 @Test
83 public void testMapGetWithTransformer() {
84 final Transformer<Number, Integer> intConverter = Number::intValue;
85 final Map<Long, Number> map = LazyMap.lazyMap(new HashMap<>(), intConverter);
86 assertEquals(0, map.size());
87 final Number i1 = map.get(123L);
88 assertEquals(123, i1);
89 assertEquals(1, map.size());
90 }
91
92
93
94
95
96
97
98
99
100
101
102
103 }