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