Update IgnoringPatternMetacharactersUnitTest.java

Implemented improvements suggested by Editor.
This commit is contained in:
Dasun Nirmitha 2021-05-10 14:54:53 +05:30
parent 0fbcc6fe5e
commit 76e45f3b08
1 changed files with 4 additions and 4 deletions

View File

@ -8,13 +8,13 @@ import java.util.regex.Pattern;
import org.junit.Test;
public class IgnoringPatternMetacharactersUnitTest {
private static final String dollarValues = "$100.25, $100.50, $150.50, $100.50, $100.75";
private static final String dollarAmounts = "$100.25, $100.50, $150.50, $100.50, $100.75";
private static final String patternStr = "$100.50";
@Test
public void givenPatternStringHasMetacharacters_whenPatternMatchedWithoutEscapingMetacharacters_thenNoMatchesFound() {
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(dollarValues);
Matcher matcher = pattern.matcher(dollarAmounts);
int matches = 0;
while (matcher.find()) {
@ -28,7 +28,7 @@ public class IgnoringPatternMetacharactersUnitTest {
public void givenPatternStringHasMetacharacters_whenPatternCompiledUsingManuallyMetaEscapedPattern_thenMatchingSuccessful() {
String metaEscapedPatternStr = "\\Q" + patternStr + "\\E";
Pattern pattern = Pattern.compile(metaEscapedPatternStr);
Matcher matcher = pattern.matcher(dollarValues);
Matcher matcher = pattern.matcher(dollarAmounts);
int matches = 0;
while (matcher.find()) {
@ -42,7 +42,7 @@ public class IgnoringPatternMetacharactersUnitTest {
public void givenPatternStringHasMetacharacters_whenPatternCompiledUsingLiteralPatternFromQuote_thenMatchingSuccessful() {
String literalPatternStr = Pattern.quote(patternStr);
Pattern pattern = Pattern.compile(literalPatternStr);
Matcher matcher = pattern.matcher(dollarValues);
Matcher matcher = pattern.matcher(dollarAmounts);
int matches = 0;
while (matcher.find()) {