BAEL-839 - minor test changes

This commit is contained in:
slavisa-baeldung 2017-05-22 06:08:39 +01:00
parent 7ceac32faf
commit 3aae854ea2
1 changed files with 67 additions and 70 deletions

View File

@ -1,70 +1,67 @@
package com.baeldung.regexp; package com.baeldung.regexp;
import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.assertThat;
import org.junit.Test; import static org.hamcrest.CoreMatchers.*;
public class EscapingCharsManualTest { import org.junit.Test;
@Test
public void givenRegexWithDot_whenMatchingStr_thenMatches() { public class EscapingCharsTest {
String strInput = "foof"; @Test
String strRegex = "foo."; public void givenRegexWithDot_whenMatchingStr_thenMatches() {
EscapingChars e = new EscapingChars(); String strInput = "foof";
String strRegex = "foo.";
assertEquals(true, e.isMatching(strInput, strRegex)); EscapingChars e = new EscapingChars();
}
assertEquals(true, e.isMatching(strInput, strRegex));
@Test }
public void givenRegexWithDotEsc_whenMatchingStr_thenNotMatching() {
String strInput = "foof"; @Test
String strRegex = "foo\\."; public void givenRegexWithDotEsc_whenMatchingStr_thenNotMatching() {
EscapingChars e = new EscapingChars(); String strInput = "foof";
String strRegex = "foo\\.";
assertEquals(false, e.isMatching(strInput, strRegex)); EscapingChars e = new EscapingChars();
}
assertEquals(false, e.isMatching(strInput, strRegex));
@Test }
public void givenRegexWithPipeEscaped_whenSplitStr_thenSplits() {
String strInput = "foo|bar|hello|world"; @Test
String strRegex = "\\Q|\\E"; public void givenRegexWithPipeEscaped_whenSplitStr_thenSplits() {
EscapingChars e = new EscapingChars(); String strInput = "foo|bar|hello|world";
String strRegex = "\\Q|\\E";
assertEquals(4, e.splitAndCountWords(strInput, strRegex)); EscapingChars e = new EscapingChars();
}
assertEquals(4, e.splitAndCountWords(strInput, strRegex));
@Test }
public void givenRegexWithPipeEscQuoteMeth_whenSplitStr_thenSplits() {
String strInput = "foo|bar|hello|world"; @Test
String strRegex = "|"; public void givenRegexWithPipeEscQuoteMeth_whenSplitStr_thenSplits() {
EscapingChars e = new EscapingChars(); String strInput = "foo|bar|hello|world";
String strRegex = "|";
assertEquals(4, EscapingChars e = new EscapingChars();
e.splitAndCountWordsUsingQuoteMethod(strInput, strRegex));
} assertEquals(4, e.splitAndCountWordsUsingQuoteMethod(strInput, strRegex));
}
@Test
public void givenRegexWithDollar_whenReplacing_thenNotReplace() { @Test
String strInput = "I gave $50 to my brother." public void givenRegexWithDollar_whenReplacing_thenNotReplace() {
+ "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 = "£"; String strReplacement = "<EFBFBD>";
String output = "I gave £50 to my brother." String output = "I gave <20>50 to my brother.He bought candy for <20>35. Now he has <20>15 left.";
+ "He bought candy for £35. Now he has £15 left."; EscapingChars e = new EscapingChars();
EscapingChars e = new EscapingChars();
assertThat(output, not(equalTo(e.changeCurrencySymbol(strInput, strRegex, strReplacement))));
assertEquals(output, }
e.changeCurrencySymbol(strInput, strRegex, strReplacement));
} @Test
public void givenRegexWithDollarEsc_whenReplacing_thenReplace() {
@Test String strInput = "I gave $50 to my brother. He bought candy for $35. Now he has $15 left.";
public void givenRegexWithDollarEsc_whenReplacing_thenReplace() { String strRegex = "\\$";
String strInput = "I gave $50 to my brother. He bought candy for $35. Now he has $15 left."; String strReplacement = "<EFBFBD>";
String strRegex = "\\$"; String output = "I gave <20>50 to my brother. He bought candy for <20>35. Now he has <20>15 left.";
String strReplacement = "£"; EscapingChars e = new EscapingChars();
String output = "I gave £50 to my brother. He bought candy for £35. Now he has £15 left.";
EscapingChars e = new EscapingChars(); assertEquals(output, e.changeCurrencySymbol(strInput, strRegex, strReplacement));
}
assertEquals(output, }
e.changeCurrencySymbol(strInput, strRegex, strReplacement));
}
}