@@ -41,9 +41,9 @@ public void setUp() {
41
41
}
42
42
private HtmlRegexExtractor htmlExtractor ;
43
43
44
- @ Test ( expected = IllegalArgumentException . class )
44
+ @ Test
45
45
public void testFindKeywordWithEmptyKeyword () {
46
- htmlExtractor .findKeyword ("" , "abc" );
46
+ assertNull ( htmlExtractor .findKeyword ("" , "abc" ) );
47
47
}
48
48
49
49
@ Test
@@ -62,12 +62,6 @@ public void testFindKeywordInSentence() {
62
62
+ "statement in long text" ));
63
63
}
64
64
65
- @ Test
66
- public void testFindKeywordInSentenceWithSpaceInKeyword () {
67
- assertEquals ("ab c" , htmlExtractor .findKeyword ("ab c" , "Wer are looking for the "
68
- + "ab c statement in long text" ));
69
- }
70
-
71
65
@ Test
72
66
public void testFindKeywordInSentenceWithSpaceInKeywordAndTextWithNBSP () {
73
67
assertEquals ("ab c" , htmlExtractor .findKeyword ("ab c" , "Wer are looking for "
@@ -108,4 +102,53 @@ public void testFindKeywordSmallestOccurrence() {
108
102
assertEquals ("Hello World" , htmlExtractor .findKeyword ("Hello World" ,
109
103
"Hello Banana Animal Text Hello World Ape" ));
110
104
}
105
+
106
+ @ Test
107
+ public void testCreateRegexWithOneCharContext () {
108
+ assertEquals ("b(.*)e" , htmlExtractor .htmlToRegexConverter ("cd" , "abcdefg" ));
109
+ }
110
+
111
+ @ Test
112
+ public void testCreateRegexWithKeywordAtStart () {
113
+ assertEquals ("(.*)c" , htmlExtractor .htmlToRegexConverter ("ab" , "abcdefg" ));
114
+ }
115
+
116
+ @ Test
117
+ public void testCreateRegexWithKeywordAtEnd () {
118
+ assertEquals ("d(.*)" , htmlExtractor .htmlToRegexConverter ("efg" , "abcdefg" ));
119
+ }
120
+
121
+ @ Test
122
+ public void testCreateRegexWithDuplicateKeywordFirstOccurrence1CharContext () {
123
+ assertEquals ("ab(.*)defga" , htmlExtractor .htmlToRegexConverter ("KEY" , "abKEYdefgadKEYdefg" ));
124
+ }
125
+
126
+ @ Test
127
+ public void testCreateRegexWith2CharContext () {
128
+ assertEquals ("yb(.*)de" , htmlExtractor .htmlToRegexConverter ("KEY" , "abcdefg ybKEYdefg" ));
129
+ }
130
+
131
+ @ Test
132
+ public void testCreateRegexWhereKeywordEqualsHtmlText () {
133
+ assertEquals ("(.*)" , htmlExtractor .htmlToRegexConverter ("abcdefg" , "abcdefg" ));
134
+ }
135
+
136
+ @ Test
137
+ public void testCreateRegexPostfixInKeyword () {
138
+ assertEquals ("(.*)b" , htmlExtractor .htmlToRegexConverter ("abc" , "abcbc" ));
139
+ }
140
+
141
+ @ Test
142
+ public void testCreateRegexOutOfBoundsAfter2CharContext () {
143
+ assertEquals ("b(.*)ba" , htmlExtractor .htmlToRegexConverter ("abc" , "babcbabcb" ));
144
+ }
145
+ @ Test
146
+ public void testFirstKeyBordersOnSecondKey () {
147
+ assertEquals ("baaaa(.*)aaaaK" , htmlExtractor .htmlToRegexConverter ("KEY" ,
148
+ "baaaaKEYaaaaKEYaaaa" ));
149
+ }
150
+ @ Test
151
+ public void testCreateRegexWhereTextOnlyKeywords () {
152
+ assertEquals ("(.*)aa" , htmlExtractor .htmlToRegexConverter ("a" , "aaa" ));
153
+ }
111
154
}
0 commit comments