### Question:
Expander { public static String expandToString( Template template, Params params, Evaluator evaluator ) { StringBuilder builder = new StringBuilder(); if( params == null ) { params = EMPTY_PARAMS; } Set<String> names = new LinkedHashSet<>( params.getNames() ); expandScheme( template, names, params, evaluator, builder ); expandAuthority( template, names, params, evaluator, builder ); expandPath( template, names, params, evaluator, builder ); if( template.hasFragment() ) { StringBuilder fragment = new StringBuilder(); expandFragment( template, names, params, evaluator, fragment ); expandQuery( template, names, params, evaluator, builder ); builder.append( fragment ); } else { expandQuery( template, names, params, evaluator, builder ); } return builder.toString(); }  static URI expand( Template template, Params params, Evaluator evaluator ); static URI expandToUri( Template template, Params params, Evaluator evaluator ); static Template expandToTemplate( Template template, Params params, Evaluator evaluator ); static String expandToString( Template template, Params params, Evaluator evaluator );  }### Answer:
@Test public void testLiteralsAndRegexInTemplates() throws Exception { String output; Matcher<Void> matcher; Matcher<Void>.Match match; Template input, template, rewrite; Evaluator evaluator; evaluator = new Evaluator() { @Override public List<String> evaluate( String function, List<String> parameters ) { return Collections.singletonList("https: } }; template = Parser.parseTemplate( "{root=ROOT}/{path=**}" ); rewrite = Parser.parseTemplate( "{root}/{path}" ); matcher = new Matcher<>(); matcher.add( template, null ); input = Parser.parseLiteral( "ROOT/child/path" ); match = matcher.match( input ); assertThat( match, notNullValue() ); output = Expander.expandToString( rewrite, match.getParams(), evaluator ); assertThat( output, is( "ROOT/child/path" ) ); template = Parser.parseTemplate( "{root={}/{path=**}" ); rewrite = Parser.parseTemplate( "{root}/{path}" ); matcher = new Matcher<>(); matcher.add( template, null ); input = Parser.parseLiteral( "{/child/path" ); match = matcher.match( input ); assertThat( match, notNullValue() ); output = Expander.expandToString( rewrite, match.getParams(), evaluator ); assertThat( output, is( "{/child/path" ) ); template = Parser.parseTemplate( "{root=}}/{path=**}" ); rewrite = Parser.parseTemplate( "{root}/{path}" ); matcher = new Matcher<>(); matcher.add( template, null ); input = Parser.parseLiteral( "}/child/path" ); match = matcher.match( input ); assertThat( match, notNullValue() ); output = Expander.expandToString( rewrite, match.getParams(), evaluator ); assertThat( output, is( "}/child/path" ) ); template = Parser.parseTemplate( "{root={}}/{path=**}" ); rewrite = Parser.parseTemplate( "{root}/{path}" ); matcher = new Matcher<>(); matcher.add( template, null ); input = Parser.parseLiteral( "{}/child/path" ); match = matcher.match( input ); assertThat( match, notNullValue() ); output = Expander.expandToString( rewrite, match.getParams(), evaluator ); assertThat( output, is( "{}/child/path" ) ); template = Parser.parseTemplate( "{var=${*}}/{path=**}" ); rewrite = Parser.parseTemplate( "{var}/{path}" ); matcher = new Matcher<>(); matcher.add( template, null ); input = Parser.parseLiteral( "${app.dir}/child/path" ); match = matcher.match( input ); assertThat( match, notNullValue() ); output = Expander.expandToString( rewrite, match.getParams(), evaluator ); assertThat( output, is( "${app.dir}/child/path" ) ); }