|
@@ -1,31 +1,75 @@
|
|
1
|
+import org.junit.Assert;
|
1
|
2
|
import org.junit.Before;
|
2
|
3
|
import org.junit.Test;
|
3
|
4
|
|
|
5
|
+import java.io.File;
|
|
6
|
+
|
4
|
7
|
import static org.junit.Assert.*;
|
|
8
|
+import java .util.*;
|
|
9
|
+import java.util.regex.Matcher;
|
|
10
|
+import java.util.regex.Pattern;
|
5
|
11
|
|
6
|
12
|
public class HamletParserTest {
|
7
|
13
|
private String hamletText;
|
8
|
14
|
private HamletParser hamletParser;
|
9
|
15
|
|
|
16
|
+
|
10
|
17
|
@Before
|
11
|
18
|
public void setUp() {
|
12
|
19
|
this.hamletParser = new HamletParser();
|
13
|
20
|
this.hamletText = hamletParser.getHamletData();
|
|
21
|
+
|
14
|
22
|
}
|
15
|
23
|
|
16
|
24
|
@Test
|
17
|
25
|
public void testChangeHamletToLeon() {
|
|
26
|
+
|
|
27
|
+ Pattern replace = Pattern.compile("Hamlet");
|
|
28
|
+ Matcher matcher2 = replace.matcher(hamletText );
|
|
29
|
+ String actual= matcher2.replaceAll("Leon") ;
|
|
30
|
+ //System.out.println(actual);
|
|
31
|
+ String expected=hamletText.toString().replaceAll("Hamlet","Leon") ;
|
|
32
|
+ Assert.assertEquals(expected,actual ) ;
|
|
33
|
+
|
|
34
|
+
|
18
|
35
|
}
|
19
|
36
|
|
20
|
37
|
@Test
|
21
|
38
|
public void testChangeHoratioToTariq() {
|
|
39
|
+
|
|
40
|
+ Pattern replace = Pattern.compile("Horatio");
|
|
41
|
+ Matcher matcher2 = replace.matcher(hamletText );
|
|
42
|
+ String actual= matcher2.replaceAll("Tariq") ;
|
|
43
|
+ //System.out.println(actual);
|
|
44
|
+ String expected=hamletText.toString().replaceAll("Horatio","Tariq") ;
|
|
45
|
+ Assert.assertEquals(expected,actual );
|
22
|
46
|
}
|
23
|
47
|
|
24
|
48
|
@Test
|
25
|
49
|
public void testFindHoratio() {
|
|
50
|
+ String regex = "Horatio";
|
|
51
|
+
|
|
52
|
+ Pattern pattern = Pattern.compile(regex);
|
|
53
|
+
|
|
54
|
+ Matcher matcher = pattern.matcher(hamletText );
|
|
55
|
+ boolean expected=matcher.find() ;
|
|
56
|
+ System.out.println(expected );
|
|
57
|
+ Assert.assertTrue(expected ) ;
|
|
58
|
+
|
|
59
|
+
|
26
|
60
|
}
|
27
|
61
|
|
28
|
62
|
@Test
|
29
|
63
|
public void testFindHamlet() {
|
|
64
|
+ // String patternString1 = "((John) (.+?)) ";
|
|
65
|
+ String regex = "((Hamlet) (.+?))";
|
|
66
|
+
|
|
67
|
+ Pattern pattern = Pattern.compile(regex);
|
|
68
|
+
|
|
69
|
+ Matcher matcher = pattern.matcher(hamletText );
|
|
70
|
+ boolean expected=matcher.find() ;
|
|
71
|
+ System.out.println(expected );
|
|
72
|
+ Assert.assertTrue(expected ) ;
|
|
73
|
+
|
30
|
74
|
}
|
31
|
75
|
}
|