Преглед на файлове

tests written and passed

Lauren Green преди 6 години
родител
ревизия
b2cbd19095
променени са 4 файла, в които са добавени 5438 реда и са изтрити 0 реда
  1. 12
    0
      pom.xml
  2. 27
    0
      src/main/java/HamletParser.java
  3. 16
    0
      src/test/java/HamletParserTest.java
  4. 5383
    0
      target/classes/hamlet.txt

+ 12
- 0
pom.xml Целия файл

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>

+ 27
- 0
src/main/java/HamletParser.java Целия файл

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

+ 16
- 0
src/test/java/HamletParserTest.java Целия файл

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.BufferedReader;
6
+
4
 import static org.junit.Assert.*;
7
 import static org.junit.Assert.*;
5
 
8
 
6
 public class HamletParserTest {
9
 public class HamletParserTest {
15
 
18
 
16
     @Test
19
     @Test
17
     public void testChangeHamletToLeon() {
20
     public void testChangeHamletToLeon() {
21
+        hamletParser.changeHamletToLeon();
22
+        Assert.assertFalse(hamletParser.findHamlet());
18
     }
23
     }
19
 
24
 
20
     @Test
25
     @Test
21
     public void testChangeHoratioToTariq() {
26
     public void testChangeHoratioToTariq() {
27
+        hamletParser.changeHoratioToTariq();
28
+        Assert.assertFalse(hamletParser.findHoratio());
29
+
22
     }
30
     }
23
 
31
 
24
     @Test
32
     @Test
25
     public void testFindHoratio() {
33
     public void testFindHoratio() {
34
+        boolean expected = hamletParser.getHamletData().toLowerCase().contains("horatio");
35
+        boolean actual = hamletParser.findHoratio();
36
+        Assert.assertEquals(expected, actual);
37
+
26
     }
38
     }
27
 
39
 
28
     @Test
40
     @Test
29
     public void testFindHamlet() {
41
     public void testFindHamlet() {
42
+        boolean expected = hamletParser.getHamletData().toLowerCase().contains("hamlet");
43
+        boolean actual = hamletParser.findHamlet();
44
+        Assert.assertEquals(expected, actual);
45
+
30
     }
46
     }
31
 }
47
 }

+ 5383
- 0
target/classes/hamlet.txt
Файловите разлики са ограничени, защото са твърде много
Целия файл