|
1 | 1 | package net.codebox.homoglyph; |
2 | 2 |
|
3 | | -import org.junit.Assert; |
4 | 3 | import org.junit.Before; |
5 | 4 | import org.junit.Test; |
6 | 5 |
|
@@ -34,69 +33,69 @@ public void setup() throws IOException { |
34 | 33 |
|
35 | 34 | @Test |
36 | 35 | public void whenTextDoesNotContainAnyTargetWords_thenNoMatchesFound(){ |
37 | | - List<Homoglyph.SearchResult> r = homoglyph.search("Nothing to see here", "TARGET"); |
| 36 | + List<SearchResult> r = homoglyph.search("Nothing to see here", "TARGET"); |
38 | 37 | assertEquals(0, r.size()); |
39 | 38 | } |
40 | 39 |
|
41 | 40 | @Test |
42 | 41 | public void whenTextIdenticalToTargetWord_thenMatchFound(){ |
43 | | - List<Homoglyph.SearchResult> r = homoglyph.search("SOIL", "SOIL"); |
| 42 | + List<SearchResult> r = homoglyph.search("SOIL", "SOIL"); |
44 | 43 | assertEquals(1, r.size()); |
45 | 44 | checkResult(r.get(0), 0, "SOIL", "SOIL"); |
46 | 45 | } |
47 | 46 |
|
48 | 47 | @Test |
49 | 48 | public void whenTextContainsTargetWord_thenMatchFound(){ |
50 | | - List<Homoglyph.SearchResult> r = homoglyph.search("I have SOIL in my garden", "SOIL"); |
| 49 | + List<SearchResult> r = homoglyph.search("I have SOIL in my garden", "SOIL"); |
51 | 50 | assertEquals(1, r.size()); |
52 | 51 | checkResult(r.get(0), 7, "SOIL", "SOIL"); |
53 | 52 | } |
54 | 53 |
|
55 | 54 | @Test |
56 | 55 | public void whenTextContainsOneOfTheTargetWords_thenMatchFound(){ |
57 | | - List<Homoglyph.SearchResult> r = homoglyph.search("I have SOIL in my garden", "CHEESE", "SOIL", "FALCONS"); |
| 56 | + List<SearchResult> r = homoglyph.search("I have SOIL in my garden", "CHEESE", "SOIL", "FALCONS"); |
58 | 57 | assertEquals(1, r.size()); |
59 | 58 | checkResult(r.get(0), 7, "SOIL", "SOIL"); |
60 | 59 | } |
61 | 60 |
|
62 | 61 | @Test |
63 | 62 | public void whenTargetWordContainsHomoglyphs_thenMatchFound(){ |
64 | | - List<Homoglyph.SearchResult> r = homoglyph.search("I have 501L in my garden", Arrays.asList("CHEESE", "SOIL", "FALCONS")); |
| 63 | + List<SearchResult> r = homoglyph.search("I have 501L in my garden", Arrays.asList("CHEESE", "SOIL", "FALCONS")); |
65 | 64 | assertEquals(1, r.size()); |
66 | 65 | checkResult(r.get(0), 7, "SOIL", "501L"); |
67 | 66 | } |
68 | 67 |
|
69 | 68 | @Test |
70 | 69 | public void whenTargetWordIsAtStartOfText_thenMatchFound(){ |
71 | | - List<Homoglyph.SearchResult> r = homoglyph.search("FALC0N5 fly", Arrays.asList("CHEESE", "SOIL", "FALCONS")); |
| 70 | + List<SearchResult> r = homoglyph.search("FALC0N5 fly", Arrays.asList("CHEESE", "SOIL", "FALCONS")); |
72 | 71 | assertEquals(1, r.size()); |
73 | 72 | checkResult(r.get(0), 0, "FALCONS", "FALC0N5"); |
74 | 73 | } |
75 | 74 |
|
76 | 75 | @Test |
77 | 76 | public void whenTargetWordIsAtEndOfText_thenMatchFound(){ |
78 | | - List<Homoglyph.SearchResult> r = homoglyph.search("I like FALC0N5", Arrays.asList("CHEESE", "SOIL", "FALCONS")); |
| 77 | + List<SearchResult> r = homoglyph.search("I like FALC0N5", Arrays.asList("CHEESE", "SOIL", "FALCONS")); |
79 | 78 | assertEquals(1, r.size()); |
80 | 79 | checkResult(r.get(0), 7, "FALCONS", "FALC0N5"); |
81 | 80 | } |
82 | 81 |
|
83 | 82 | @Test |
84 | 83 | public void whenTargetWordHasDifferentCaseInText_thenMatchFound(){ |
85 | | - List<Homoglyph.SearchResult> r = homoglyph.search("I like fALc0N5 fly", "Falcons"); |
| 84 | + List<SearchResult> r = homoglyph.search("I like fALc0N5 fly", "Falcons"); |
86 | 85 | assertEquals(1, r.size()); |
87 | 86 | checkResult(r.get(0), 7, "Falcons", "fALc0N5"); |
88 | 87 | } |
89 | 88 |
|
90 | 89 | @Test |
91 | 90 | public void whenTargetWordContainsMultipleMatchesWithDifferentHomoglyphs_thenMatchFound(){ |
92 | | - List<Homoglyph.SearchResult> r = homoglyph.search("I have 501L and FALC0N5 in my garden, I prefer the SO|L", Arrays.asList("CHEESE", "SOIL", "FALCONS")); |
| 91 | + List<SearchResult> r = homoglyph.search("I have 501L and FALC0N5 in my garden, I prefer the SO|L", Arrays.asList("CHEESE", "SOIL", "FALCONS")); |
93 | 92 | assertEquals(3, r.size()); |
94 | 93 | checkResult(r.get(0), 7, "SOIL", "501L"); |
95 | 94 | checkResult(r.get(1), 51, "SOIL", "SO|L"); |
96 | 95 | checkResult(r.get(2), 16, "FALCONS", "FALC0N5"); |
97 | 96 | } |
98 | 97 |
|
99 | | - private void checkResult(Homoglyph.SearchResult result, int expectedIndex, String expectedWord, String expectedMatch){ |
| 98 | + private void checkResult(SearchResult result, int expectedIndex, String expectedWord, String expectedMatch){ |
100 | 99 | assertEquals(expectedIndex, result.index); |
101 | 100 | assertEquals(expectedWord, result.word); |
102 | 101 | assertEquals(expectedMatch, result.match); |
|
0 commit comments