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>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/HamletParser.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import java.io.File;
import java.io.IOException;
import java.util.Formatter;
import java.util.Scanner;

/**
Expand All @@ -8,6 +9,7 @@
public class HamletParser {

private String hamletData;
private Formatter formatter;

public HamletParser(){
this.hamletData = loadFile();
Expand Down
34 changes: 34 additions & 0 deletions src/test/java/HamletParserTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.junit.Assert.*;

public class HamletParserTest {
Expand All @@ -15,17 +19,47 @@ public void setUp() {

@Test
public void testChangeHamletToLeon() {
Pattern pattern = Pattern.compile("Hamlet");
Matcher matcher = pattern.matcher(hamletText);
String result = matcher.replaceAll("Leon");

System.out.println(result);
}

@Test
public void testChangeHoratioToTariq() {
Pattern pattern = Pattern.compile("Horatio");
Matcher matcher = pattern.matcher(hamletText);
String result = matcher.replaceAll("Tariq");

Boolean hasOldName = result.indexOf("Horatio") != -1;

Assert.assertFalse(hasOldName);
}

@Test
public void testFindHoratio() {
Pattern pattern = Pattern.compile("Horatio");
Matcher matcher = pattern.matcher(hamletText);
Integer count = 0;

while (matcher.find()){
count++;
}

Assert.assertTrue(count > 0);
}

@Test
public void testFindHamlet() {
Pattern pattern = Pattern.compile("Hamlet");
Matcher matcher = pattern.matcher(hamletText);
Integer count = 0;

while (matcher.find()){
count++;
}

Assert.assertTrue(count > 0);
}
}
Loading