Przeglądaj źródła

Merge pull request #208 from FridaTveit/MakeAnagramTestsUseJUnit

Issue #193: Changed assertions in AnagramTest to use junit instead of…

(resolves #193)
John Ryan 9 lat temu
rodzic
commit
83002e9ec3

+ 0
- 1
exercises/anagram/build.gradle Wyświetl plik

@@ -8,7 +8,6 @@ repositories {
8 8
 
9 9
 dependencies {
10 10
   testCompile "junit:junit:4.12"
11
-  testCompile "org.assertj:assertj-core:3.2.0"
12 11
 }
13 12
 test {
14 13
   testLogging {

+ 17
- 13
exercises/anagram/src/test/java/AnagramTest.java Wyświetl plik

@@ -1,9 +1,11 @@
1
-import static org.assertj.core.api.Assertions.assertThat;
1
+import org.junit.Ignore;
2
+import org.junit.Test;
2 3
 
3 4
 import java.util.Arrays;
4 5
 import java.util.List;
5
-import org.junit.Test;
6
-import org.junit.Ignore;
6
+
7
+import static org.hamcrest.CoreMatchers.*;
8
+import static org.junit.Assert.*;
7 9
 
8 10
 public class AnagramTest {
9 11
 
@@ -11,7 +13,7 @@ public class AnagramTest {
11 13
     @Test
12 14
     public void testNoMatches() {
13 15
         Anagram detector = new Anagram("diaper");
14
-        assertThat(detector.match(Arrays.asList("hello", "world", "zombies", "pants"))).isEmpty();
16
+        assertTrue(detector.match(Arrays.asList("hello", "world", "zombies", "pants")).isEmpty());
15 17
     }
16 18
 
17 19
     @Ignore
@@ -19,7 +21,8 @@ public class AnagramTest {
19 21
     public void testSimpleAnagram() {
20 22
         Anagram detector = new Anagram("ant");
21 23
         List<String> anagram = detector.match(Arrays.asList("tan", "stand", "at"));
22
-        assertThat(anagram).containsExactly("tan");
24
+        assertThat(anagram, hasItem("tan"));
25
+        assertThat(anagram.size(), is(1));
23 26
     }
24 27
 
25 28
     @Ignore
@@ -27,7 +30,7 @@ public class AnagramTest {
27 30
     public void testDetectMultipleAnagrams() {
28 31
         Anagram detector = new Anagram("master");
29 32
         List<String> anagrams = detector.match(Arrays.asList("stream", "pigeon", "maters"));
30
-        assertThat(anagrams).contains("maters", "stream");
33
+        assertThat(anagrams, allOf(hasItem("maters"), hasItem("stream")));
31 34
     }
32 35
 
33 36
     @Ignore
@@ -35,7 +38,7 @@ public class AnagramTest {
35 38
     public void testDoesNotConfuseDifferentDuplicates() {
36 39
         Anagram detector = new Anagram("galea");
37 40
         List<String> anagrams = detector.match(Arrays.asList("eagle"));
38
-        assertThat(anagrams).isEmpty();
41
+        assertTrue(anagrams.isEmpty());
39 42
     }
40 43
 
41 44
     @Ignore
@@ -43,21 +46,22 @@ public class AnagramTest {
43 46
     public void testIdenticalWordIsNotAnagram() {
44 47
         Anagram detector = new Anagram("corn");
45 48
         List<String> anagrams = detector.match(Arrays.asList("corn", "dark", "Corn", "rank", "CORN", "cron", "park"));
46
-        assertThat(anagrams).containsExactly("cron");
49
+        assertThat(anagrams, hasItem("cron"));
50
+        assertThat(anagrams.size(), is(1));
47 51
     }
48 52
 
49 53
     @Ignore
50 54
     @Test
51 55
     public void testEliminateAnagramsWithSameChecksum() {
52 56
         Anagram detector = new Anagram("mass");
53
-        assertThat(detector.match(Arrays.asList("last")).isEmpty());
57
+        assertTrue(detector.match(Arrays.asList("last")).isEmpty());
54 58
     }
55 59
 
56 60
     @Ignore
57 61
     @Test
58 62
     public void testEliminateAnagramSubsets() {
59 63
         Anagram detector = new Anagram("good");
60
-        assertThat(detector.match(Arrays.asList("dog", "goody"))).isEmpty();
64
+        assertTrue(detector.match(Arrays.asList("dog", "goody")).isEmpty());
61 65
     }
62 66
 
63 67
     @Ignore
@@ -65,7 +69,7 @@ public class AnagramTest {
65 69
     public void testDetectAnagrams() {
66 70
         Anagram detector = new Anagram("listen");
67 71
         List<String> anagrams = detector.match(Arrays.asList("enlists", "google", "inlets", "banana"));
68
-        assertThat(anagrams).contains("inlets");
72
+        assertThat(anagrams, hasItem("inlets"));
69 73
     }
70 74
 
71 75
     @Ignore
@@ -73,7 +77,7 @@ public class AnagramTest {
73 77
     public void testMultipleAnagrams() {
74 78
         Anagram detector = new Anagram("allergy");
75 79
         List<String> anagrams = detector.match(Arrays.asList("gallery", "ballerina", "regally", "clergy", "largely", "leading"));
76
-        assertThat(anagrams).contains("gallery", "largely", "regally");
80
+        assertThat(anagrams, allOf(hasItem("gallery"), hasItem("largely"), hasItem("regally")));
77 81
     }
78 82
 
79 83
     @Ignore
@@ -81,7 +85,7 @@ public class AnagramTest {
81 85
     public void testAnagramsAreCaseInsensitive() {
82 86
         Anagram detector = new Anagram("Orchestra");
83 87
         List<String> anagrams = detector.match(Arrays.asList("cashregister", "Carthorse", "radishes"));
84
-        assertThat(anagrams).contains("Carthorse");
88
+        assertThat(anagrams, hasItem("Carthorse"));
85 89
     }
86 90
 
87 91
 }