Explorar el Código

completed lab

Christian Sheridan hace 6 años
padre
commit
05b8601857
Se han modificado 4 ficheros con 5432 adiciones y 1 borrados
  1. 13
    0
      pom.xml
  2. 27
    0
      src/main/java/HamletParser.java
  3. 9
    1
      src/test/java/HamletParserTest.java
  4. 5383
    0
      target/classes/hamlet.txt

+ 13
- 0
pom.xml Ver fichero

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

+ 27
- 0
src/main/java/HamletParser.java Ver fichero

@@ -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,29 @@ public class HamletParser {
36 38
         return hamletData;
37 39
     }
38 40
 
41
+
42
+    public void toLeon() {
43
+
44
+        Pattern pattern = Pattern.compile("hamlet", Pattern.CASE_INSENSITIVE);
45
+        Matcher matcher = pattern.matcher(hamletData);
46
+        hamletData = matcher.replaceAll("Leon");
47
+
48
+    }
49
+
50
+    public boolean findHamlet() {
51
+
52
+        return hamletData.toLowerCase().contains("hamlet");
53
+    }
54
+
55
+    public boolean findHoratio() {
56
+        return hamletData.toLowerCase().contains("horatio");
57
+    }
58
+
59
+    public void toTariq() {
60
+
61
+        Pattern pattern = Pattern.compile("horatio", Pattern.CASE_INSENSITIVE);
62
+        Matcher matcher = pattern.matcher(hamletData);
63
+        hamletData = matcher.replaceAll("Tariq");
64
+
65
+    }
39 66
 }

+ 9
- 1
src/test/java/HamletParserTest.java Ver fichero

@@ -1,11 +1,13 @@
1
+import org.junit.Assert;
1 2
 import org.junit.Before;
2 3
 import org.junit.Test;
3 4
 
4 5
 import static org.junit.Assert.*;
5 6
 
6 7
 public class HamletParserTest {
7
-    private String hamletText;
8
+
8 9
     private HamletParser hamletParser;
10
+    private String hamletText;
9 11
 
10 12
     @Before
11 13
     public void setUp() {
@@ -15,17 +17,23 @@ public class HamletParserTest {
15 17
 
16 18
     @Test
17 19
     public void testChangeHamletToLeon() {
20
+        hamletParser.toLeon();
21
+        Assert.assertFalse(hamletParser.findHamlet());
18 22
     }
19 23
 
20 24
     @Test
21 25
     public void testChangeHoratioToTariq() {
26
+        hamletParser.toTariq();
27
+        Assert.assertFalse(hamletParser.findHoratio());
22 28
     }
23 29
 
24 30
     @Test
25 31
     public void testFindHoratio() {
32
+        Assert.assertTrue(hamletParser.findHoratio());
26 33
     }
27 34
 
28 35
     @Test
29 36
     public void testFindHamlet() {
37
+        Assert.assertTrue(hamletParser.findHamlet());
30 38
     }
31 39
 }

+ 5383
- 0
target/classes/hamlet.txt
La diferencia del archivo ha sido suprimido porque es demasiado grande
Ver fichero