Ejemplo n.º 1
0
  @Test
  public void testReplace() throws Exception {
    String inString = "a6AazAaa77abaa";
    String oldPattern = "aa";
    String newPattern = "foo";

    // Simple replace
    String s = StringUtils.replace(inString, oldPattern, newPattern);
    assertTrue("Replace 1 worked", s.equals("a6AazAfoo77abfoo"));

    // Non match: no change
    s = StringUtils.replace(inString, "qwoeiruqopwieurpoqwieur", newPattern);
    assertTrue("Replace non matched is equal", s.equals(inString));

    // Null new pattern: should ignore
    s = StringUtils.replace(inString, oldPattern, null);
    assertTrue("Replace non matched is equal", s.equals(inString));

    // Null old pattern: should ignore
    s = StringUtils.replace(inString, null, newPattern);
    assertTrue("Replace non matched is equal", s.equals(inString));
  }