BAEL-839 changes in all test methods

This commit is contained in:
buddhini81 2017-05-29 17:55:10 +05:30 committed by GitHub
parent 3e28582bac
commit 4586d471a1

View File

@ -11,57 +11,59 @@ public class EscapingCharsTest {
public void givenRegexWithDot_whenMatchingStr_thenMatches() { public void givenRegexWithDot_whenMatchingStr_thenMatches() {
String strInput = "foof"; String strInput = "foof";
String strRegex = "foo."; String strRegex = "foo.";
EscapingChars e = new EscapingChars();
assertEquals(true, strInput.matches(strRegex));
assertEquals(true, e.isMatching(strInput, strRegex));
} }
@Test @Test
public void givenRegexWithDotEsc_whenMatchingStr_thenNotMatching() { public void givenRegexWithDotEsc_whenMatchingStr_thenNotMatching() {
String strInput = "foof"; String strInput = "foof";
String strRegex = "foo\\."; String strRegex = "foo\\.";
EscapingChars e = new EscapingChars();
assertEquals(false, strInput.matches(strRegex));
assertEquals(false, e.isMatching(strInput, strRegex));
} }
@Test @Test
public void givenRegexWithPipeEscaped_whenSplitStr_thenSplits() { public void givenRegexWithPipeEscaped_whenSplitStr_thenSplits() {
String strInput = "foo|bar|hello|world"; String strInput = "foo|bar|hello|world";
String strRegex = "\\Q|\\E"; String strRegex = "\\Q|\\E";
EscapingChars e = new EscapingChars();
assertEquals(4, strInput.split(strRegex).length);
assertEquals(4, e.splitAndCountWords(strInput, strRegex));
} }
@Test @Test
public void givenRegexWithPipeEscQuoteMeth_whenSplitStr_thenSplits() { public void givenRegexWithPipeEscQuoteMeth_whenSplitStr_thenSplits() {
String strInput = "foo|bar|hello|world"; String strInput = "foo|bar|hello|world";
String strRegex = "|"; String strRegex = "|";
EscapingChars e = new EscapingChars();
assertEquals(4,strInput.split(Pattern.quote(strRegex)).length);
assertEquals(4, e.splitAndCountWordsUsingQuoteMethod(strInput, strRegex));
} }
@Test @Test
public void givenRegexWithDollar_whenReplacing_thenNotReplace() { public void givenRegexWithDollar_whenReplacing_thenNotReplace() {
String strInput = "I gave $50 to my brother.He bought candy for $35. Now he has $15 left."; String strInput = "I gave $50 to my brother."
+ "He bought candy for $35. Now he has $15 left.";
String strRegex = "$"; String strRegex = "$";
String strReplacement = "<EFBFBD>"; String strReplacement = "£";
String output = "I gave <20>50 to my brother.He bought candy for <20>35. Now he has <20>15 left."; String output = "I gave £50 to my brother."
EscapingChars e = new EscapingChars(); + "He bought candy for £35. Now he has £15 left.";
Pattern p = Pattern.compile(strRegex);
assertThat(output, not(equalTo(e.changeCurrencySymbol(strInput, strRegex, strReplacement)))); Matcher m = p.matcher(strInput);
assertThat(output, not(equalTo(m.replaceAll(strReplacement))));
} }
@Test @Test
public void givenRegexWithDollarEsc_whenReplacing_thenReplace() { public void givenRegexWithDollarEsc_whenReplacing_thenReplace() {
String strInput = "I gave $50 to my brother. He bought candy for $35. Now he has $15 left."; String strInput = "I gave $50 to my brother."
+ "He bought candy for $35. Now he has $15 left.";
String strRegex = "\\$"; String strRegex = "\\$";
String strReplacement = "<EFBFBD>"; String strReplacement = "£";
String output = "I gave <20>50 to my brother. He bought candy for <20>35. Now he has <20>15 left."; String output = "I gave £50 to my brother."
EscapingChars e = new EscapingChars(); + "He bought candy for £35. Now he has £15 left.";
Pattern p = Pattern.compile(strRegex);
assertEquals(output, e.changeCurrencySymbol(strInput, strRegex, strReplacement)); Matcher m = p.matcher(strInput);
assertEquals(output,m.replaceAll(strReplacement));
} }
} }