|
@@ -1,6 +1,10 @@
|
|
1
|
+import org.junit.Assert;
|
1
|
2
|
import org.junit.Before;
|
2
|
3
|
import org.junit.Test;
|
3
|
4
|
|
|
5
|
+import java.util.regex.Matcher;
|
|
6
|
+import java.util.regex.Pattern;
|
|
7
|
+
|
4
|
8
|
import static org.junit.Assert.*;
|
5
|
9
|
|
6
|
10
|
public class HamletParserTest {
|
|
@@ -15,17 +19,35 @@ public class HamletParserTest {
|
15
|
19
|
|
16
|
20
|
@Test
|
17
|
21
|
public void testChangeHamletToLeon() {
|
|
22
|
+ String expected = hamletParser.changeName("(h|H)amlet", "Leon", this.hamletText);
|
|
23
|
+ Assert.assertFalse(expected.contains("(h|H)amlet"));
|
18
|
24
|
}
|
19
|
25
|
|
20
|
26
|
@Test
|
21
|
27
|
public void testChangeHoratioToTariq() {
|
|
28
|
+ String expected = hamletParser.changeName("(h|H)oratio", "Tariq", this.hamletText);
|
|
29
|
+ Assert.assertFalse(expected.contains("(h|H)oratio"));
|
22
|
30
|
}
|
23
|
31
|
|
24
|
32
|
@Test
|
25
|
33
|
public void testFindHoratio() {
|
|
34
|
+ String testHoratioStr = "My name is Horatio";
|
|
35
|
+ String horatioPattern = ("(h|H)oratio");
|
|
36
|
+
|
|
37
|
+ String expected = "My name is Tariq";
|
|
38
|
+ String actual = hamletParser.changeName(horatioPattern, "Tariq", testHoratioStr);
|
|
39
|
+
|
|
40
|
+ Assert.assertEquals(expected, actual);
|
26
|
41
|
}
|
27
|
42
|
|
28
|
43
|
@Test
|
29
|
44
|
public void testFindHamlet() {
|
|
45
|
+ String testHoratioStr = "My name is Hamlet, hamlet";
|
|
46
|
+ String hamletPattern = ("(h|H)amlet");
|
|
47
|
+
|
|
48
|
+ String expected = "My name is Leon, Leon";
|
|
49
|
+ String actual = hamletParser.changeName(hamletPattern, "Leon", testHoratioStr);
|
|
50
|
+
|
|
51
|
+ Assert.assertEquals(expected, actual);
|
30
|
52
|
}
|
31
|
53
|
}
|