Przeglądaj źródła

Merge pull request #246 from FridaTveit/RefactorWordCountTests

Issue #167: Refactored WordCountTest to have a setup method
John Ryan 9 lat temu
rodzic
commit
6c1ae656a5

+ 10
- 13
exercises/word-count/src/test/java/WordCountTest.java Wyświetl plik

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