-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathHamletParserTest.java
More file actions
69 lines (55 loc) · 1.78 KB
/
HamletParserTest.java
File metadata and controls
69 lines (55 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static org.junit.Assert.*;
public class HamletParserTest {
private String hamletText;
private HamletParser hamletParser;
@Before
public void setUp() {
this.hamletParser = new HamletParser();
this.hamletText = hamletParser.getHamletData();
}
@Test
public void testChangeHamletToLeon() {
Pattern pattern = Pattern.compile("Hamlet");
Matcher matcher = pattern.matcher(hamletText);
String finalResult = matcher.replaceAll("Leon");
System.out.println(finalResult);
Boolean hasHamlet = finalResult.indexOf("Hamlet") != -1;
Assert.assertFalse(hasHamlet);
}
@Test
public void testChangeHoratioToTariq() {
Pattern pattern = Pattern.compile("Horatio");
Matcher matcher = pattern.matcher(hamletText);
String finalResult = matcher.replaceAll("Tariq");
System.out.println(finalResult);
Boolean hasHoratio = finalResult.indexOf("Horatio") != -1;
Assert.assertFalse(hasHoratio);
}
@Test
public void testFindHoratio() {
Pattern pattern = Pattern.compile("Horatio");
Matcher matcher = pattern.matcher(hamletText);
Integer count = 0;
while (matcher.find()){
count++;
}
System.out.println(count);
Assert.assertTrue(count > 0);
}
@Test
public void testFindHamlet() {
Pattern pattern = Pattern.compile("Hamlet");
Matcher matcher = pattern.matcher(hamletText);
Integer count = 0;
while(matcher.find()){
count++;
}
System.out.println(count);
Assert.assertTrue(count > 0);
}
}