Yesoda Sanka 6 anos atrás
pai
commit
c06c1dba66
4 arquivos alterados com 5445 adições e 0 exclusões
  1. 12
    0
      pom.xml
  2. 6
    0
      src/main/java/HamletParser.java
  3. 44
    0
      src/test/java/HamletParserTest.java
  4. 5383
    0
      target/classes/hamlet.txt

+ 12
- 0
pom.xml Ver arquivo

@@ -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>

+ 6
- 0
src/main/java/HamletParser.java Ver arquivo

@@ -33,7 +33,13 @@ public class HamletParser {
33 33
     }
34 34
 
35 35
     public String getHamletData(){
36
+
36 37
         return hamletData;
37 38
     }
38 39
 
40
+   /* public void  changeHamletToLeon (String matchingText, String replaceText ) {
41
+
42
+        hamletData.replaceAll(matchingText, replaceText);
43
+    }*/
44
+
39 45
 }

+ 44
- 0
src/test/java/HamletParserTest.java Ver arquivo

@@ -1,31 +1,75 @@
1
+import org.junit.Assert;
1 2
 import org.junit.Before;
2 3
 import org.junit.Test;
3 4
 
5
+import java.io.File;
6
+
4 7
 import static org.junit.Assert.*;
8
+import java .util.*;
9
+import java.util.regex.Matcher;
10
+import java.util.regex.Pattern;
5 11
 
6 12
 public class HamletParserTest {
7 13
     private String hamletText;
8 14
     private HamletParser hamletParser;
9 15
 
16
+
10 17
     @Before
11 18
     public void setUp() {
12 19
         this.hamletParser = new HamletParser();
13 20
         this.hamletText = hamletParser.getHamletData();
21
+
14 22
     }
15 23
 
16 24
     @Test
17 25
     public void testChangeHamletToLeon() {
26
+
27
+        Pattern replace = Pattern.compile("Hamlet");
28
+        Matcher matcher2 = replace.matcher(hamletText );
29
+       String actual=   matcher2.replaceAll("Leon") ;
30
+       //System.out.println(actual);
31
+        String expected=hamletText.toString().replaceAll("Hamlet","Leon") ;
32
+       Assert.assertEquals(expected,actual  )  ;
33
+
34
+
18 35
     }
19 36
 
20 37
     @Test
21 38
     public void testChangeHoratioToTariq() {
39
+
40
+        Pattern replace = Pattern.compile("Horatio");
41
+        Matcher matcher2 = replace.matcher(hamletText );
42
+        String actual=   matcher2.replaceAll("Tariq") ;
43
+        //System.out.println(actual);
44
+        String expected=hamletText.toString().replaceAll("Horatio","Tariq") ;
45
+        Assert.assertEquals(expected,actual  );
22 46
     }
23 47
 
24 48
     @Test
25 49
     public void testFindHoratio() {
50
+        String regex = "Horatio";
51
+
52
+        Pattern pattern = Pattern.compile(regex);
53
+
54
+        Matcher matcher = pattern.matcher(hamletText );
55
+        boolean expected=matcher.find() ;
56
+        System.out.println(expected );
57
+        Assert.assertTrue(expected ) ;
58
+
59
+
26 60
     }
27 61
 
28 62
     @Test
29 63
     public void testFindHamlet() {
64
+       // String patternString1 = "((John) (.+?)) ";
65
+        String regex = "((Hamlet) (.+?))";
66
+
67
+        Pattern pattern = Pattern.compile(regex);
68
+
69
+        Matcher matcher = pattern.matcher(hamletText );
70
+        boolean expected=matcher.find() ;
71
+        System.out.println(expected );
72
+        Assert.assertTrue(expected ) ;
73
+
30 74
     }
31 75
 }

+ 5383
- 0
target/classes/hamlet.txt
Diferenças do arquivo suprimidas por serem muito extensas
Ver arquivo