|
@@ -1,6 +1,9 @@
|
1
|
1
|
import org.junit.Before;
|
2
|
2
|
import org.junit.Test;
|
3
|
3
|
|
|
4
|
+import java.util.regex.Matcher;
|
|
5
|
+import java.util.regex.Pattern;
|
|
6
|
+
|
4
|
7
|
import static org.junit.Assert.*;
|
5
|
8
|
|
6
|
9
|
public class HamletParserTest {
|
|
@@ -14,18 +17,52 @@ public class HamletParserTest {
|
14
|
17
|
}
|
15
|
18
|
|
16
|
19
|
@Test
|
17
|
|
- public void testChangeHamletToLeon() {
|
|
20
|
+ public void testChangeHamletToDolio() {
|
|
21
|
+ String input = "HamletHoratioHamletHoratio";
|
|
22
|
+ String find = "Hamlet";
|
|
23
|
+ String replace = "Dolio";
|
|
24
|
+ Pattern pattern = hamletParser.createRegexPattern(find);
|
|
25
|
+ Matcher matcher = hamletParser.createMatcherFromInput(pattern, input);
|
|
26
|
+ String actual = hamletParser.findReplace(matcher, replace);
|
|
27
|
+ String expected = "DolioHoratioDolioHoratio";
|
|
28
|
+ assertEquals(expected, actual);
|
18
|
29
|
}
|
19
|
30
|
|
20
|
31
|
@Test
|
21
|
|
- public void testChangeHoratioToTariq() {
|
|
32
|
+ public void testChangeHoratioToFroilan() {
|
|
33
|
+ String input = "HamletHoratioHamletHoratio";
|
|
34
|
+ String find = "Horatio";
|
|
35
|
+ String replace = "Froilan";
|
|
36
|
+ Pattern pattern = hamletParser.createRegexPattern(find);
|
|
37
|
+ Matcher matcher = hamletParser.createMatcherFromInput(pattern, input);
|
|
38
|
+ String actual = hamletParser.findReplace(matcher, replace);
|
|
39
|
+ String expected = "HamletFroilanHamletFroilan";
|
|
40
|
+ assertEquals(expected, actual);
|
22
|
41
|
}
|
23
|
42
|
|
24
|
43
|
@Test
|
25
|
|
- public void testFindHoratio() {
|
|
44
|
+ public void testCreateHoratioPattern() {
|
|
45
|
+ String expected = "Horatio";
|
|
46
|
+ Pattern pattern = hamletParser.createRegexPattern(expected);
|
|
47
|
+ String actual = pattern.toString();
|
|
48
|
+ assertEquals(expected, actual);
|
26
|
49
|
}
|
27
|
50
|
|
28
|
51
|
@Test
|
29
|
|
- public void testFindHamlet() {
|
|
52
|
+ public void testCreateHamletPattern() {
|
|
53
|
+ String expected = "Hamlet";
|
|
54
|
+ Pattern pattern = hamletParser.createRegexPattern(expected);
|
|
55
|
+ String actual = pattern.toString();
|
|
56
|
+ assertEquals(expected, actual);
|
30
|
57
|
}
|
|
58
|
+
|
|
59
|
+ @Test
|
|
60
|
+ public void testCreateMatcherFromInput(){
|
|
61
|
+ String input = "HamletHoratioHamletHoratio";
|
|
62
|
+ Pattern pattern = hamletParser.createRegexPattern("Hamlet");
|
|
63
|
+ Matcher matcher = hamletParser.createMatcherFromInput(pattern, input);
|
|
64
|
+ boolean actual = matcher instanceof Matcher;
|
|
65
|
+ assertTrue(actual);
|
|
66
|
+ }
|
|
67
|
+
|
31
|
68
|
}
|