Yesoda Sanka vor 6 Jahren
Ursprung
Commit
c06c1dba66
4 geänderte Dateien mit 5445 neuen und 0 gelöschten Zeilen
  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 Datei anzeigen

7
     <groupId>com.zipcodewilmington</groupId>
7
     <groupId>com.zipcodewilmington</groupId>
8
     <artifactId>regex</artifactId>
8
     <artifactId>regex</artifactId>
9
     <version>1.0-SNAPSHOT</version>
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
     <dependencies>
23
     <dependencies>
12
         <dependency>
24
         <dependency>

+ 6
- 0
src/main/java/HamletParser.java Datei anzeigen

33
     }
33
     }
34
 
34
 
35
     public String getHamletData(){
35
     public String getHamletData(){
36
+
36
         return hamletData;
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 Datei anzeigen

1
+import org.junit.Assert;
1
 import org.junit.Before;
2
 import org.junit.Before;
2
 import org.junit.Test;
3
 import org.junit.Test;
3
 
4
 
5
+import java.io.File;
6
+
4
 import static org.junit.Assert.*;
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
 public class HamletParserTest {
12
 public class HamletParserTest {
7
     private String hamletText;
13
     private String hamletText;
8
     private HamletParser hamletParser;
14
     private HamletParser hamletParser;
9
 
15
 
16
+
10
     @Before
17
     @Before
11
     public void setUp() {
18
     public void setUp() {
12
         this.hamletParser = new HamletParser();
19
         this.hamletParser = new HamletParser();
13
         this.hamletText = hamletParser.getHamletData();
20
         this.hamletText = hamletParser.getHamletData();
21
+
14
     }
22
     }
15
 
23
 
16
     @Test
24
     @Test
17
     public void testChangeHamletToLeon() {
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
     @Test
37
     @Test
21
     public void testChangeHoratioToTariq() {
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
     @Test
48
     @Test
25
     public void testFindHoratio() {
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
     @Test
62
     @Test
29
     public void testFindHamlet() {
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
Datei-Diff unterdrückt, da er zu groß ist
Datei anzeigen