### Question:
RewriteConfig implements RewriteRule { @Override public Optional<String> rewrite(String originalUri) { Matcher matcher = compiledUrlPattern.matcher(originalUri); if (matcher.matches()) { return Optional.of(preprocessedReplacement.substitute(matcher)); } return Optional.empty(); } RewriteConfig(String urlPattern, String replacement); String urlPattern(); String replacement(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Override Optional<String> rewrite(String originalUri);  }### Answer:
@Test public void testSubstitutions() { String urlPattern = "\\/foo\\/(a|b|c)(\\/.*)?"; RewriteConfig config = new RewriteConfig(urlPattern, "/bar/$1$2"); assertThat(config.rewrite("/foo/b/something").get(), CoreMatchers.equalTo("/bar/b/something")); config = new RewriteConfig(urlPattern, "/bar/$1/x$2"); assertThat(config.rewrite("/foo/b/something").get(), CoreMatchers.equalTo("/bar/b/x/something")); config = new RewriteConfig(urlPattern, "/bar/$1/x$2/y"); assertThat(config.rewrite("/foo/b/something").get(), CoreMatchers.equalTo("/bar/b/x/something/y")); config = new RewriteConfig(urlPattern, "$1/x$2/y"); assertThat(config.rewrite("/foo/b/something").get(), CoreMatchers.equalTo("b/x/something/y")); config = new RewriteConfig(urlPattern, "$1$2/y"); assertThat(config.rewrite("/foo/b/something").get(), CoreMatchers.equalTo("b/something/y")); config = new RewriteConfig(urlPattern, "$1$2"); assertThat(config.rewrite("/foo/b/something").get(), CoreMatchers.equalTo("b/something")); }