Skip to content

Commit

Permalink
Add a test for Matcher.replaceAll()
Browse files Browse the repository at this point in the history
  • Loading branch information
izeye committed Feb 19, 2020
1 parent 3ed5b8e commit 9001596
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/test/java/learningtest/java/util/regex/PatternTests.java
Expand Up @@ -104,5 +104,15 @@ public void replaceAllWithCapturingGroup() {
assertThat(pattern.matcher("\"ab\"").replaceAll("\\\\$1")).isEqualTo("\\\"ab\\\"");
assertThat(pattern.matcher("\"a,b\"").replaceAll("\\\\$1")).isEqualTo("\\\"a\\,b\\\"");
}

@Test
public void replaceAllWhenNoMatchReturnsInputItself() {
Pattern pattern = Pattern.compile("/$");

String uriPath = "/persons";
String replacedUriPath = pattern.matcher(uriPath).replaceAll("");
assertThat(replacedUriPath).isSameAs(uriPath);
assertThat(pattern.matcher("/persons/").replaceAll("")).isEqualTo(uriPath);
}

}

0 comments on commit 9001596

Please sign in to comment.