Skip to content
Open

fin #25

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
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@
<version>4.12</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

</project>
2 changes: 2 additions & 0 deletions src/main/java/HamletParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ public String getHamletData(){
return hamletData;
}



}
38 changes: 38 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,51 @@ 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);
Boolean hasOldName = result.contains("Hamlet");

Assert.assertFalse(hasOldName);
}

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

System.out.println(result);
Boolean hasOldName = result.contains("Horatio");

Assert.assertFalse(hasOldName);
}

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

while(matcher.find()){ // works similar to has next
count++;
}
System.out.println(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