-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathHamletParserTest.java
More file actions
68 lines (54 loc) · 1.71 KB
/
HamletParserTest.java
File metadata and controls
68 lines (54 loc) · 1.71 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
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 result = matcher.replaceAll("Leon");
System.out.println(result);
Boolean hasOldName = result.contains("Hamlet");
Assert.assertFalse(hasOldName);
}
@Test
public void testChangeHoratioToTariq() {
Pattern pattern = Pattern.compile("Horatio");
Matcher matcher = pattern.matcher(hamletText);
String result = matcher.replaceAll("Tariq");
System.out.println(result);
Boolean hasOldName = result.contains("Horatio");
Assert.assertFalse(hasOldName);
}
@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++;
}
Assert.assertTrue(count > 0);
}
}