-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapTest.java
More file actions
54 lines (44 loc) · 1.75 KB
/
Copy pathMapTest.java
File metadata and controls
54 lines (44 loc) · 1.75 KB
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
package api.java.util.map;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
public class MapTest {
@Test
public void givenMap_whenComputeSumKeyValue_ThenValuesAssignedSumKeyValue() {
final Map<Integer, Integer> mapActual = new HashMap<Integer, Integer>() {{
put(1, 1);
put(2, 2);
put(3, 3);
}};
final Map<Integer, Integer> mapExpected = new HashMap<Integer, Integer>() {{
put(1, 2);
put(2, 4);
put(3, 6);
}};
// key is remapped into key + value
mapActual.forEach((key, value) -> mapActual.compute(key, (key1, value1) -> key1 + value1));
assertThat(mapActual).isNotNull().hasSize(3).isEqualTo(mapExpected);
}
@Test
public void mapBooleanTest() {
final Map<String, String> mapBoolean = new HashMap<String, String>() {{
put("1", "true");
put("0", "false");
put("false", "false");
put("true", "true");
}};
String booleanValue = "0";
assertThat(mapBoolean.get(booleanValue.toLowerCase())).isEqualTo("false");
booleanValue = "1";
assertThat(mapBoolean.get(booleanValue.toLowerCase())).isEqualTo("true");
booleanValue = "false";
assertThat(mapBoolean.get(booleanValue.toLowerCase())).isEqualTo("false");
booleanValue = "true";
assertThat(mapBoolean.get(booleanValue.toLowerCase())).isEqualTo("true");
booleanValue = "FALSE";
assertThat(mapBoolean.get(booleanValue.toLowerCase())).isEqualTo("false");
booleanValue = "TRUE";
assertThat(mapBoolean.get(booleanValue.toLowerCase())).isEqualTo("true");
}
}