Bläddra i källkod

Did i do it right?

Akeem Cherry 6 år sedan
förälder
incheckning
09b83d08a6
4 ändrade filer med 5430 tillägg och 0 borttagningar
  1. 12
    0
      pom.xml
  2. 26
    0
      src/main/java/HamletParser.java
  3. 9
    0
      src/test/java/HamletParserTest.java
  4. 5383
    0
      target/classes/hamlet.txt

+ 12
- 0
pom.xml Visa fil

@@ -7,6 +7,18 @@
7 7
     <groupId>com.zipcodewilmington</groupId>
8 8
     <artifactId>regex</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <build>
11
+        <plugins>
12
+            <plugin>
13
+                <groupId>org.apache.maven.plugins</groupId>
14
+                <artifactId>maven-compiler-plugin</artifactId>
15
+                <configuration>
16
+                    <source>7</source>
17
+                    <target>7</target>
18
+                </configuration>
19
+            </plugin>
20
+        </plugins>
21
+    </build>
10 22
 
11 23
     <dependencies>
12 24
         <dependency>

+ 26
- 0
src/main/java/HamletParser.java Visa fil

@@ -1,6 +1,8 @@
1 1
 import java.io.File;
2 2
 import java.io.IOException;
3 3
 import java.util.Scanner;
4
+import java.util.regex.Matcher;
5
+import java.util.regex.Pattern;
4 6
 
5 7
 /**
6 8
  * Created by thook on 10/7/15.
@@ -36,4 +38,28 @@ public class HamletParser {
36 38
         return hamletData;
37 39
     }
38 40
 
41
+    public void changeHamletToLeon() {
42
+        Pattern hamletPattern = Pattern.compile("Hamlet", Pattern.CASE_INSENSITIVE);
43
+        Matcher hamletMatcher = hamletPattern.matcher(hamletData);
44
+        hamletData = hamletMatcher.replaceAll("Leon");
45
+    }
46
+
47
+
48
+    public void changeHoratioToTariq() {
49
+        Pattern horatioPattern = Pattern.compile("Horatio", Pattern.CASE_INSENSITIVE);
50
+        Matcher horatioMatcher = horatioPattern.matcher(hamletData);
51
+        hamletData = horatioMatcher.replaceAll("Tariq");
52
+    }
53
+
54
+    public boolean findHamlet() {
55
+        Pattern hamletPattern = Pattern.compile("Hamlet", Pattern.CASE_INSENSITIVE);
56
+        Matcher hamletMatcher = hamletPattern.matcher(hamletData);
57
+        return hamletMatcher.find();
58
+    }
59
+
60
+    public boolean findHoratio() {
61
+        Pattern horatioPattern = Pattern.compile("Horatio", Pattern.CASE_INSENSITIVE);
62
+        Matcher horatioMatcher = horatioPattern.matcher(hamletData);
63
+        return horatioMatcher.find();
64
+    }
39 65
 }

+ 9
- 0
src/test/java/HamletParserTest.java Visa fil

@@ -1,3 +1,4 @@
1
+import org.junit.Assert;
1 2
 import org.junit.Before;
2 3
 import org.junit.Test;
3 4
 
@@ -15,17 +16,25 @@ public class HamletParserTest {
15 16
 
16 17
     @Test
17 18
     public void testChangeHamletToLeon() {
19
+        hamletParser.changeHamletToLeon();
20
+        Assert.assertFalse(hamletParser.findHamlet());
18 21
     }
19 22
 
20 23
     @Test
21 24
     public void testChangeHoratioToTariq() {
25
+        hamletParser.changeHoratioToTariq();
26
+        Assert.assertFalse(hamletParser.findHoratio());
22 27
     }
23 28
 
24 29
     @Test
25 30
     public void testFindHoratio() {
31
+        boolean expected = hamletParser.findHoratio();
32
+        Assert.assertTrue(expected);
26 33
     }
27 34
 
28 35
     @Test
29 36
     public void testFindHamlet() {
37
+        boolean expected = hamletParser.findHamlet();
38
+        Assert.assertTrue(expected);
30 39
     }
31 40
 }

+ 5383
- 0
target/classes/hamlet.txt
Filskillnaden har hållits tillbaka eftersom den är för stor
Visa fil