|
@@ -2,61 +2,69 @@ import org.junit.Assert;
|
2
|
2
|
import org.junit.Before;
|
3
|
3
|
import org.junit.Test;
|
4
|
4
|
|
|
5
|
+import java.util.regex.Matcher;
|
|
6
|
+import java.util.regex.Pattern;
|
|
7
|
+
|
5
|
8
|
import static org.junit.Assert.*;
|
6
|
9
|
|
7
|
10
|
public class HamletParserTest {
|
8
|
11
|
private String hamletText;
|
9
|
12
|
private HamletParser hamletParser;
|
10
|
13
|
private ReplaceNames replaceNames;
|
|
14
|
+ private Pattern pattern;
|
|
15
|
+
|
11
|
16
|
|
12
|
17
|
@Before
|
13
|
18
|
public void setUp() {
|
14
|
19
|
this.hamletParser = new HamletParser();
|
15
|
20
|
this.hamletText = hamletParser.getHamletData();
|
16
|
21
|
this.replaceNames = new ReplaceNames();
|
|
22
|
+
|
17
|
23
|
}
|
18
|
24
|
|
19
|
25
|
@Test
|
20
|
26
|
public void testChangeHamletToLeon() {
|
|
27
|
+ Pattern leonPattern = pattern.compile("[Leon]");
|
|
28
|
+ Matcher leonMatcher = leonPattern.matcher(hamletText);
|
|
29
|
+ hamletText = replaceNames.replaceHamlet(hamletText);
|
|
30
|
+ Assert.assertTrue(leonMatcher.find());
|
21
|
31
|
}
|
22
|
32
|
|
23
|
33
|
@Test
|
24
|
34
|
public void testChangeHoratioToTariq() {
|
|
35
|
+ Pattern leonPattern = pattern.compile("[Tariq]");
|
|
36
|
+ Matcher tariqMatcher = leonPattern.matcher(hamletText);
|
|
37
|
+ hamletText = replaceNames.replaceHoratio(hamletText);
|
|
38
|
+ Assert.assertTrue(tariqMatcher.find());
|
25
|
39
|
}
|
26
|
40
|
|
27
|
|
- @Test
|
28
|
|
- public void testIsHoratioTrue(){
|
29
|
|
- boolean actual = replaceNames.isHoratio("hORatIo's");
|
30
|
|
- Assert.assertTrue(actual);
|
31
|
|
- }
|
32
|
41
|
|
33
|
|
- @Test
|
34
|
|
- public void testIsHoratioFalse(){
|
35
|
|
- boolean actual = replaceNames.isHoratio("notHoratio");
|
36
|
|
- Assert.assertFalse(actual);
|
37
|
|
- }
|
38
|
42
|
|
39
|
43
|
@Test
|
40
|
44
|
public void testFindHoratio() {
|
41
|
|
- String test = "Horatio, horatio test test HORATIO, hORatIo";
|
42
|
|
- int actual = replaceNames.findHoratio(test);
|
43
|
|
- int expected = 4;
|
44
|
|
- Assert.assertEquals(expected, actual);
|
|
45
|
+ boolean actual = replaceNames.findHoratio(hamletText);
|
|
46
|
+ Assert.assertTrue(actual);
|
45
|
47
|
}
|
46
|
48
|
|
|
49
|
+
|
47
|
50
|
@Test
|
48
|
|
- public void testIsHamletTrue(){
|
49
|
|
- boolean actual = replaceNames.isHamlet("HamLet's");
|
|
51
|
+ public void testFindHamlet() {
|
|
52
|
+ boolean actual =replaceNames.findHamlet(hamletText);
|
50
|
53
|
Assert.assertTrue(actual);
|
51
|
54
|
}
|
52
|
55
|
|
53
|
56
|
@Test
|
54
|
|
- public void testIsHamletFalse(){
|
55
|
|
- boolean actual = replaceNames.isHamlet("notHamLet");
|
|
57
|
+ public void testReplaceHoratio() {
|
|
58
|
+ hamletText = replaceNames.replaceHoratio(hamletText);
|
|
59
|
+ boolean actual = replaceNames.findHoratio(hamletText);
|
56
|
60
|
Assert.assertFalse(actual);
|
57
|
61
|
}
|
58
|
62
|
|
|
63
|
+
|
59
|
64
|
@Test
|
60
|
|
- public void testFindHamlet() {
|
|
65
|
+ public void testReplaceHamlet() {
|
|
66
|
+ hamletText = replaceNames.replaceHamlet(hamletText);
|
|
67
|
+ boolean actual =replaceNames.findHamlet(hamletText);
|
|
68
|
+ Assert.assertFalse(actual);
|
61
|
69
|
}
|
62
|
70
|
}
|