1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
package org.openecomp.sdc.be.dao.utils;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import org.junit.Test;
public class MapUtilTest {
@Test
public void testGet() throws Exception {
Map<String, ? extends Object> map = null;
String path = "";
Object result;
// default test
result = MapUtil.get(map, path);
path = "\\mock\\mock";
result = MapUtil.get(map, path);
}
@Test
public void testGroupListBy() throws Exception {
Collection valuesToMap = new LinkedList<String>();
Function<String, String> groupingFunction = new Function<String, String>() {
@Override
public String apply(String t) {
return t;
}
};
Map<String, List<String>> result;
// default test
result = MapUtil.groupListBy(valuesToMap, groupingFunction);
}
@Test
public void testToMap() throws Exception {
Collection<String> valuesToMap = null;
Function<String, String> mappingFunction = null;
Map<String, String> result;
// default test
result = MapUtil.toMap(valuesToMap, mappingFunction);
}
@Test
public void testConvertMapKeys() throws Exception {
Map<String, List<String>> map = new HashMap<>();
Function<String, String> keyMappingFunction = new Function<String, String>() {
@Override
public String apply(String t) {
return t;
}
};
Map<String, List<String>> result;
// default test
result = MapUtil.convertMapKeys(map, keyMappingFunction);
}
@Test
public void testNewHashMap() throws Exception {
String[] keys = new String[] { "mock" };
String[] values = new String[] { "mock" };
Map<String, String> result;
// test 1
result = MapUtil.newHashMap(keys, values);
//Assert.assertEquals(null, result);
// test 2
keys = new String[] { "mock" };
values = null;
try {
result = MapUtil.newHashMap(keys, values);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// test 3
values = null;
keys = null;
try {
result = MapUtil.newHashMap(keys, values);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Assert.assertEquals(null, result);
// test 4
values = new String[] { "mock" };
keys = null;
try {
result = MapUtil.newHashMap(keys, values);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
|