Skip to content
Open
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
30 changes: 30 additions & 0 deletions src/main/java/HamletParser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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 +38,32 @@ public String getHamletData(){
return hamletData;
}

public static String changeHamletToLeon(String input){
Pattern pattern=Pattern.compile("Hamlet",Pattern.CASE_INSENSITIVE);
Matcher matcher=pattern.matcher(input);
return matcher.replaceAll("Leon");
}

public static String changeHoratioToTariq(String input){
Pattern pattern=Pattern.compile("Horatio",Pattern.CASE_INSENSITIVE);
Matcher matcher=pattern.matcher(input);
return matcher.replaceAll("Tariq");
}

public static boolean findHoratio(String input){
Pattern pattern=Pattern.compile("Horatio",Pattern.CASE_INSENSITIVE);
Matcher matcher= pattern.matcher(input);
if(matcher.find())
return true;
return false;
}

public static boolean findHamlet(String input){
Pattern pattern=Pattern.compile("Hamlet");
Matcher matcher= pattern.matcher(input);
if(matcher.find())
return true;
return false;
}

}
19 changes: 19 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,35 @@ public void setUp() {

@Test
public void testChangeHamletToLeon() {
//given
String expectedValue="His fell to Leon";
String input="His fell to Hamlet";
//when
String actualValue=HamletParser.changeHamletToLeon(input);
//then
Assert.assertEquals(expectedValue,actualValue);
}

@Test
public void testChangeHoratioToTariq() {
//given
String expectedValue="If you do meet Tariq and Marcellus";
String input="If you do meet Horatio and Marcellus";
//when
String actualValue=HamletParser.changeHoratioToTariq(input);
//then
Assert.assertEquals(expectedValue,actualValue);
}

@Test
public void testFindHoratio() {
boolean actualValue = HamletParser.findHoratio(hamletText);
Assert.assertTrue(actualValue);
}

@Test
public void testFindHamlet() {
boolean actualValue=HamletParser.findHamlet(hamletText);
Assert.assertTrue(actualValue);
}
}
Loading