Просмотр исходного кода

Issue #167: Refactored WordCountTest to have a setup method

Frida Tveit 9 лет назад
Родитель
Сommit
ad26030777
1 измененных файлов: 10 добавлений и 13 удалений
  1. 10
    13
      exercises/word-count/src/test/java/WordCountTest.java

+ 10
- 13
exercises/word-count/src/test/java/WordCountTest.java Просмотреть файл

@@ -1,3 +1,4 @@
1
+import org.junit.Before;
1 2
 import org.junit.Test;
2 3
 import org.junit.Ignore;
3 4
 
@@ -10,13 +11,19 @@ import static org.junit.Assert.*;
10 11
 
11 12
 public class WordCountTest {
12 13
 
13
-    private final WordCount wordCount = new WordCount();
14
+    private WordCount wordCount;
15
+    private Map<String, Integer> actualWordCount;
16
+    private Map<String, Integer> expectedWordCount;
17
+
18
+    @Before
19
+    public void setup() {
20
+        wordCount = new WordCount();
21
+        expectedWordCount = new HashMap<String, Integer>();
22
+    }
14 23
 
15 24
 
16 25
     @Test
17 26
     public void countOneWord() {
18
-        Map<String, Integer> actualWordCount = new HashMap<String, Integer>();
19
-        final Map<String, Integer> expectedWordCount = new HashMap<String, Integer>();
20 27
         expectedWordCount.put("word", 1);
21 28
 
22 29
         actualWordCount = wordCount.phrase("word");
@@ -28,8 +35,6 @@ public class WordCountTest {
28 35
     @Ignore
29 36
     @Test
30 37
     public void countOneOfEach() {
31
-        Map<String, Integer> actualWordCount = new HashMap<String, Integer>();
32
-        final Map<String, Integer> expectedWordCount = new HashMap<String, Integer>();
33 38
         expectedWordCount.put("one", 1);
34 39
         expectedWordCount.put("of", 1);
35 40
         expectedWordCount.put("each", 1);
@@ -43,8 +48,6 @@ public class WordCountTest {
43 48
     @Ignore
44 49
     @Test
45 50
     public void countMultipleOccurences() {
46
-        Map<String, Integer> actualWordCount = new HashMap<String, Integer>();
47
-        final Map<String, Integer> expectedWordCount = new HashMap<String, Integer>();
48 51
         expectedWordCount.put("one", 1);
49 52
         expectedWordCount.put("fish", 4);
50 53
         expectedWordCount.put("two", 1);
@@ -60,8 +63,6 @@ public class WordCountTest {
60 63
     @Ignore
61 64
     @Test
62 65
     public void ignorePunctuation() {
63
-        Map<String, Integer> actualWordCount = new HashMap<String, Integer>();
64
-        final Map<String, Integer> expectedWordCount = new HashMap<String, Integer>();
65 66
         expectedWordCount.put("car", 1);
66 67
         expectedWordCount.put("carpet", 1);
67 68
         expectedWordCount.put("as", 1);
@@ -78,8 +79,6 @@ public class WordCountTest {
78 79
     @Ignore
79 80
     @Test
80 81
     public void includeNumbers() {
81
-        Map<String, Integer> actualWordCount = new HashMap<String, Integer>();
82
-        final Map<String, Integer> expectedWordCount = new HashMap<String, Integer>();
83 82
         expectedWordCount.put("testing", 2);
84 83
         expectedWordCount.put("1", 1);
85 84
         expectedWordCount.put("2", 1);
@@ -93,8 +92,6 @@ public class WordCountTest {
93 92
     @Ignore
94 93
     @Test
95 94
     public void normalizeCase() {
96
-        Map<String, Integer> actualWordCount = new HashMap<String, Integer>();
97
-        final Map<String, Integer> expectedWordCount = new HashMap<String, Integer>();
98 95
         expectedWordCount.put("go", 3);
99 96
 
100 97
         actualWordCount = wordCount.phrase("go Go GO");