|
@@ -1,6 +1,11 @@
|
|
1
|
+import com.sun.org.apache.xpath.internal.operations.Bool;
|
|
2
|
+import org.junit.Assert;
|
1
|
3
|
import org.junit.Before;
|
2
|
4
|
import org.junit.Test;
|
3
|
5
|
|
|
6
|
+import java.util.regex.Matcher;
|
|
7
|
+import java.util.regex.Pattern;
|
|
8
|
+
|
4
|
9
|
import static org.junit.Assert.*;
|
5
|
10
|
|
6
|
11
|
public class HamletParserTest {
|
|
@@ -15,17 +20,47 @@ public class HamletParserTest {
|
15
|
20
|
|
16
|
21
|
@Test
|
17
|
22
|
public void testChangeHamletToLeon() {
|
|
23
|
+ Pattern pattern = Pattern.compile("Hamlet");
|
|
24
|
+ Matcher m = pattern.matcher(hamletText);
|
|
25
|
+ String actual = m.replaceAll("Leon");
|
|
26
|
+
|
|
27
|
+ String expected = hamletText.toString().replaceAll("Hamlet","Leon");
|
|
28
|
+
|
|
29
|
+ Assert.assertEquals(expected,actual);
|
18
|
30
|
}
|
19
|
31
|
|
20
|
32
|
@Test
|
21
|
33
|
public void testChangeHoratioToTariq() {
|
22
|
|
- }
|
|
34
|
+ Pattern pattern = Pattern.compile("Horatio");
|
|
35
|
+ Matcher cher = pattern.matcher(hamletText);
|
|
36
|
+ String actual = cher.replaceAll("Tariq");
|
|
37
|
+
|
|
38
|
+ String expected = hamletText.toString().replaceAll("Horatio","Tariq");
|
23
|
39
|
|
|
40
|
+ Assert.assertEquals(expected,actual);
|
|
41
|
+ }
|
|
42
|
+//
|
24
|
43
|
@Test
|
25
|
44
|
public void testFindHoratio() {
|
|
45
|
+
|
|
46
|
+ String regex = "((Horatio) (.+?))";
|
|
47
|
+ Pattern pattern=Pattern.compile(regex );
|
|
48
|
+ Matcher mat =pattern.matcher(hamletText);
|
|
49
|
+
|
|
50
|
+ Boolean expected = mat.find();
|
|
51
|
+
|
|
52
|
+ Assert.assertTrue(expected);
|
|
53
|
+
|
26
|
54
|
}
|
27
|
55
|
|
28
|
56
|
@Test
|
29
|
57
|
public void testFindHamlet() {
|
|
58
|
+ String regex = "((Hamlet) (.+?))";
|
|
59
|
+ Pattern pattern = Pattern.compile(regex);
|
|
60
|
+ Matcher m = pattern.matcher(hamletText);
|
|
61
|
+
|
|
62
|
+ Boolean expected = m.find();
|
|
63
|
+ Assert.assertTrue(expected);
|
|
64
|
+
|
30
|
65
|
}
|
31
|
66
|
}
|