Sfoglia il codice sorgente

Remove Guava and use JUnit assert (#170)

* remove Guava and use JUnit assert

* reassign old to Collection.unmodifiable

* reassign variable expected
Alessandro Baffa 9 anni fa
parent
commit
912013d9a6
1 ha cambiato i file con 101 aggiunte e 55 eliminazioni
  1. 101
    55
      exercises/etl/src/test/java/EtlTest.java

+ 101
- 55
exercises/etl/src/test/java/EtlTest.java Vedi File

@@ -1,79 +1,125 @@
1
-import com.google.common.collect.ImmutableMap;
2 1
 import org.junit.Test;
3
-import org.junit.Ignore;
4 2
 
5
-import java.util.Arrays;
6
-import java.util.List;
7
-import java.util.Map;
3
+import java.util.*;
4
+
5
+import static org.junit.Assert.assertEquals;
8 6
 
9
-import static org.assertj.core.api.Assertions.assertThat;
10 7
 
11 8
 public class EtlTest {
12 9
     private final Etl etl = new Etl();
13 10
 
14
-
15 11
     @Test
16 12
     public void testTransformOneValue() {
17
-        Map<Integer, List<String>> old = ImmutableMap.of(1, Arrays.asList("A"));
18
-        Map<String, Integer> expected = ImmutableMap.of("a", 1);
13
+        Map<Integer, List<String>> old = new HashMap<Integer, List<String>>() {
14
+            {
15
+                put(1, Arrays.asList("A"));
16
+            }
17
+        };
18
+        old = Collections.unmodifiableMap(old);
19
+
20
+        Map<String, Integer> expected = new HashMap<String, Integer>() {
21
+            {
22
+                put("a", 1);
23
+            }
24
+        };
25
+        expected = Collections.unmodifiableMap(expected);
19 26
 
20
-        assertThat(etl.transform(old)).isEqualTo(expected);
27
+        assertEquals(etl.transform(old), expected);
21 28
     }
22 29
 
23
-    @Ignore
24 30
     @Test
25 31
     public void testTransformMoreValues() {
26
-        Map<Integer, List<String>> old = ImmutableMap.of(
27
-                1, Arrays.asList("A", "E", "I", "O", "U")
28
-        );
29
-        Map<String, Integer> expected = ImmutableMap.of(
30
-                "a", 1,
31
-                "e", 1,
32
-                "i", 1,
33
-                "o", 1,
34
-                "u", 1
35
-        );
36
-
37
-        assertThat(etl.transform(old)).isEqualTo(expected);
32
+        Map<Integer, List<String>> old = new HashMap<Integer, List<String>>() {
33
+            {
34
+                put(1, Arrays.asList("A", "E", "I", "O", "U"));
35
+            }
36
+        };
37
+        old = Collections.unmodifiableMap(old);
38
+
39
+        Map<String, Integer> expected = new HashMap<String, Integer>() {
40
+            {
41
+                put("a", 1);
42
+                put("e", 1);
43
+                put("i", 1);
44
+                put("o", 1);
45
+                put("u", 1);
46
+            }
47
+        };
48
+        expected = Collections.unmodifiableMap(expected);
49
+
50
+        assertEquals(etl.transform(old), expected);
38 51
     }
39 52
 
40
-    @Ignore
41 53
     @Test
42 54
     public void testMoreKeys() {
43
-        Map<Integer, List<String>> old = ImmutableMap.of(
44
-                1, Arrays.asList("A", "E"),
45
-                2, Arrays.asList("D", "G")
46
-        );
47
-        Map<String, Integer> expected = ImmutableMap.of(
48
-                "a", 1,
49
-                "e", 1,
50
-                "d", 2,
51
-                "g", 2
52
-        );
53
-
54
-        assertThat(etl.transform(old)).isEqualTo(expected);
55
+        Map<Integer, List<String>> old = new HashMap<Integer, List<String>>() {
56
+            {
57
+                put(1, Arrays.asList("A", "E"));
58
+                put(2, Arrays.asList("D", "G"));
59
+            }
60
+        };
61
+        old = Collections.unmodifiableMap(old);
62
+
63
+        Map<String, Integer> expected = new HashMap<String, Integer>() {
64
+            {
65
+                put("a", 1);
66
+                put("e", 1);
67
+                put("d", 2);
68
+                put("g", 2);
69
+            }
70
+        };
71
+        expected = Collections.unmodifiableMap(expected);
72
+
73
+        assertEquals(etl.transform(old), expected);
55 74
     }
56 75
 
57
-    @Ignore
58 76
     @Test
59 77
     public void testFullDataset() {
60
-        Map<Integer, List<String>> old = ImmutableMap.<Integer, List<String>>builder().
61
-                put(1, Arrays.asList("A", "E", "I", "O", "U", "L", "N", "R", "S", "T")).
62
-                put(2, Arrays.asList("D", "G")).
63
-                put(3, Arrays.asList("B", "C", "M", "P")).
64
-                put(4, Arrays.asList("F", "H", "V", "W", "Y")).
65
-                put(5, Arrays.asList("K")).
66
-                put(8, Arrays.asList("J", "X")).
67
-                put(10, Arrays.asList("Q", "Z")).
68
-                build();
69
-        Map<String, Integer> expected = ImmutableMap.<String, Integer>builder().
70
-                put("a", 1).put("b", 3).put("c", 3).put("d", 2).put("e", 1).
71
-                put("f", 4).put("g", 2).put("h", 4).put("i", 1).put("j", 8).
72
-                put("k", 5).put("l", 1).put("m", 3).put("n", 1).put("o", 1).
73
-                put("p", 3).put("q", 10).put("r", 1).put("s", 1).put("t", 1).
74
-                put("u", 1).put("v", 4).put("w", 4).put("x", 8).put("y", 4).
75
-                put("z", 10).build();
76
-
77
-        assertThat(etl.transform(old)).isEqualTo(expected);
78
+        Map<Integer, List<String>> old = new HashMap<Integer, List<String>>() {
79
+            {
80
+                put(1, Arrays.asList("A", "E", "I", "O", "U", "L", "N", "R", "S", "T"));
81
+                put(2, Arrays.asList("D", "G"));
82
+                put(3, Arrays.asList("B", "C", "M", "P"));
83
+                put(4, Arrays.asList("F", "H", "V", "W", "Y"));
84
+                put(5, Arrays.asList("K"));
85
+                put(8, Arrays.asList("J", "X"));
86
+                put(10, Arrays.asList("Q", "Z"));
87
+            }
88
+        };
89
+        old = Collections.unmodifiableMap(old);
90
+
91
+        Map<String, Integer> expected = new HashMap<String, Integer>() {
92
+            {
93
+                put("a", 1);
94
+                put("b", 3);
95
+                put("c", 3);
96
+                put("d", 2);
97
+                put("e", 1);
98
+                put("f", 4);
99
+                put("g", 2);
100
+                put("h", 4);
101
+                put("i", 1);
102
+                put("j", 8);
103
+                put("k", 5);
104
+                put("l", 1);
105
+                put("m", 3);
106
+                put("n", 1);
107
+                put("o", 1);
108
+                put("p", 3);
109
+                put("q", 10);
110
+                put("r", 1);
111
+                put("s", 1);
112
+                put("t", 1);
113
+                put("u", 1);
114
+                put("v", 4);
115
+                put("w", 4);
116
+                put("x", 8);
117
+                put("y", 4);
118
+                put("z", 10);
119
+            }
120
+        };
121
+        expected = Collections.unmodifiableMap(expected);
122
+
123
+        assertEquals(etl.transform(old), expected);
78 124
     }
79 125
 }