Skip to content

Commit 4586d47

Browse files
authored
BAEL-839 changes in all test methods
1 parent 3e28582 commit 4586d47

1 file changed

Lines changed: 31 additions & 29 deletions

File tree

‎core-java/src/test/java/com/baeldung/regexp/EscapingCharsTest.java‎

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,57 +11,59 @@ public class EscapingCharsTest {
1111
public void givenRegexWithDot_whenMatchingStr_thenMatches() {
1212
String strInput = "foof";
1313
String strRegex = "foo.";
14-
EscapingChars e = new EscapingChars();
15-
16-
assertEquals(true, e.isMatching(strInput, strRegex));
14+
15+
assertEquals(true, strInput.matches(strRegex));
1716
}
18-
17+
1918
@Test
2019
public void givenRegexWithDotEsc_whenMatchingStr_thenNotMatching() {
2120
String strInput = "foof";
2221
String strRegex = "foo\\.";
23-
EscapingChars e = new EscapingChars();
24-
25-
assertEquals(false, e.isMatching(strInput, strRegex));
22+
23+
assertEquals(false, strInput.matches(strRegex));
2624
}
27-
25+
2826
@Test
2927
public void givenRegexWithPipeEscaped_whenSplitStr_thenSplits() {
3028
String strInput = "foo|bar|hello|world";
3129
String strRegex = "\\Q|\\E";
32-
EscapingChars e = new EscapingChars();
33-
34-
assertEquals(4, e.splitAndCountWords(strInput, strRegex));
30+
31+
assertEquals(4, strInput.split(strRegex).length);
3532
}
36-
33+
3734
@Test
3835
public void givenRegexWithPipeEscQuoteMeth_whenSplitStr_thenSplits() {
3936
String strInput = "foo|bar|hello|world";
4037
String strRegex = "|";
41-
EscapingChars e = new EscapingChars();
42-
43-
assertEquals(4, e.splitAndCountWordsUsingQuoteMethod(strInput, strRegex));
38+
39+
assertEquals(4,strInput.split(Pattern.quote(strRegex)).length);
4440
}
45-
41+
4642
@Test
4743
public void givenRegexWithDollar_whenReplacing_thenNotReplace() {
48-
String strInput = "I gave $50 to my brother.He bought candy for $35. Now he has $15 left.";
44+
String strInput = "I gave $50 to my brother."
45+
+ "He bought candy for $35. Now he has $15 left.";
4946
String strRegex = "$";
50-
String strReplacement = "�";
51-
String output = "I gave �50 to my brother.He bought candy for �35. Now he has �15 left.";
52-
EscapingChars e = new EscapingChars();
53-
54-
assertThat(output, not(equalTo(e.changeCurrencySymbol(strInput, strRegex, strReplacement))));
47+
String strReplacement = "£";
48+
String output = "I gave £50 to my brother."
49+
+ "He bought candy for £35. Now he has £15 left.";
50+
Pattern p = Pattern.compile(strRegex);
51+
Matcher m = p.matcher(strInput);
52+
53+
assertThat(output, not(equalTo(m.replaceAll(strReplacement))));
5554
}
56-
55+
5756
@Test
5857
public void givenRegexWithDollarEsc_whenReplacing_thenReplace() {
59-
String strInput = "I gave $50 to my brother. He bought candy for $35. Now he has $15 left.";
58+
String strInput = "I gave $50 to my brother."
59+
+ "He bought candy for $35. Now he has $15 left.";
6060
String strRegex = "\\$";
61-
String strReplacement = "�";
62-
String output = "I gave �50 to my brother. He bought candy for �35. Now he has �15 left.";
63-
EscapingChars e = new EscapingChars();
64-
65-
assertEquals(output, e.changeCurrencySymbol(strInput, strRegex, strReplacement));
61+
String strReplacement = "£";
62+
String output = "I gave £50 to my brother."
63+
+ "He bought candy for £35. Now he has £15 left.";
64+
Pattern p = Pattern.compile(strRegex);
65+
Matcher m = p.matcher(strInput);
66+
67+
assertEquals(output,m.replaceAll(strReplacement));
6668
}
6769
}

0 commit comments

Comments
 (0)