Przeglądaj źródła

updated methods

Christian Sheridan 6 lat temu
rodzic
commit
0020290f6f

+ 6
- 2
src/main/java/HamletParser.java Wyświetl plik

@@ -49,11 +49,15 @@ public class HamletParser {
49 49
 
50 50
     public boolean findHamlet() {
51 51
 
52
-        return hamletData.toLowerCase().contains("hamlet");
52
+        Pattern pattern = Pattern.compile("hamlet", Pattern.CASE_INSENSITIVE);
53
+        Matcher matcher = pattern.matcher(hamletData);
54
+        return matcher.find();
53 55
     }
54 56
 
55 57
     public boolean findHoratio() {
56
-        return hamletData.toLowerCase().contains("horatio");
58
+        Pattern pattern = Pattern.compile("horatio", Pattern.CASE_INSENSITIVE);
59
+        Matcher matcher = pattern.matcher(hamletData);
60
+        return matcher.find();
57 61
     }
58 62
 
59 63
     public void toTariq() {

+ 10
- 0
src/test/java/HamletParserTest.java Wyświetl plik

@@ -16,6 +16,16 @@ public class HamletParserTest {
16 16
     }
17 17
 
18 18
     @Test
19
+    public void findHamletTest(){
20
+        Assert.assertTrue(hamletParser.findHamlet());
21
+    }
22
+
23
+    @Test
24
+    public void findHoratioTest(){
25
+        Assert.assertTrue(hamletParser.findHoratio());
26
+    }
27
+
28
+    @Test
19 29
     public void testChangeHamletToLeon() {
20 30
         hamletParser.toLeon();
21 31
         Assert.assertFalse(hamletParser.findHamlet());