Skip to content
Open

Done #12

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
<groupId>com.zipcodewilmington</groupId>
<artifactId>regex</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/HamletParser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import com.sun.xml.internal.rngom.digested.DPattern;

import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
* Created by thook on 10/7/15.
Expand Down Expand Up @@ -36,4 +41,46 @@ public String getHamletData(){
return hamletData;
}

public String changeHamletToLeon(){
Pattern pattern = Pattern.compile("(Hamlet)",Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(hamletData);
boolean matchFound = matcher.find();
String newString = hamletData;

if(matchFound){
newString = matcher.replaceAll("Leon");
}
return newString;
}

public String changeHoratioToTariq(){
Pattern pattern = Pattern.compile("(Horatio)",Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(hamletData);
boolean matchFound = matcher.find();
String newString = hamletData;

if(matchFound){
newString = matcher.replaceAll("Tariq");
}
return newString;
}
public boolean findHoratio(){
Pattern pattern = Pattern.compile("(Horatio)",Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(hamletData);
boolean matchFound = matcher.find();
if(matchFound){
return true;
}
return false;
}
public boolean findHamlet(){
Pattern pattern = Pattern.compile("(Hamlet)",Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(hamletData);
boolean matchFound = matcher.find();
if(matchFound){
return true;
}
return false;
}

}
25 changes: 25 additions & 0 deletions src/test/java/HamletParserTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

Expand All @@ -15,17 +16,41 @@ public void setUp() {

@Test
public void testChangeHamletToLeon() {
//Action
String actual = hamletParser.changeHamletToLeon();
System.out.println(actual);

//Assert
Assert.assertFalse(actual.contains("Hamlet"));
Assert.assertFalse(actual.contains("hamlet"));
}

@Test
public void testChangeHoratioToTariq() {
//Action
String actual = hamletParser.changeHoratioToTariq();
System.out.println(actual);

//Assert
Assert.assertFalse(actual.contains("Horatio"));
Assert.assertFalse(actual.contains("horatio"));
}

@Test
public void testFindHoratio() {
//Action
boolean actual = hamletParser.findHoratio();

//Assert
Assert.assertTrue(actual);
}

@Test
public void testFindHamlet() {
//Action
boolean actual = hamletParser.findHamlet();

//
Assert.assertTrue(actual);
}
}
Loading