### Question:
SnippetProcessor { public String process(SnippetProcessorContext ctx, String snippet) { checkNotNull(ctx); StringBuilder sb = ctx.builder(); sb.setLength(0); String currSnippet = snippet; boolean processedMacros = false; int snippetPos = 0; int macroPos = currSnippet.indexOf("${"); while (macroPos != -1) { sb.append(currSnippet.substring(snippetPos, macroPos)); int macroEnd = processMacroAt(ctx, currSnippet, macroPos); if (macroEnd == -1) { sb.append("${"); snippetPos = macroPos + 2; } else { snippetPos = macroEnd; processedMacros = true; } macroPos = currSnippet.indexOf("${", snippetPos); } if (processedMacros) { sb.append(currSnippet, snippetPos, currSnippet.length()); currSnippet = sb.toString(); } sb.setLength(0); String ret = urlEncode(ctx, currSnippet); sb.setLength(0); return ret; } SnippetProcessor(); static Escaper getEscaper(); String process(SnippetProcessorContext ctx, String snippet); @Override final String toString(); static final SnippetProcessor NULL; }### Answer:
@Test public void testNullProcessor() { SnippetProcessorContext ctx = new SnippetProcessorContext(req, resp); ctx.setBid(bid); String snippet = OpenRtbMacros.AUCTION_ID.key(); assertThat(SnippetProcessor.NULL.process(ctx, snippet)).isSameInstanceAs(snippet); }
@Test public void testUrlEncoding() { assertThat(process("")).isEqualTo(""); assertThat(process("{!+/}")).isEqualTo("{!+/}"); assertThat(process("%!+/%")).isEqualTo("%!+/%"); assertThat(process("%{aaa}%")).isEqualTo(esc("aaa")); assertThat(process("%{!+/}%")).isEqualTo(esc("!+/")); assertThat(process("%{!+/}%%{aaa}%")).isEqualTo(esc("!+/") + esc("aaa")); assertThat(process("%{%{!+/}%aaa}%")).isEqualTo(esc2("!+/") + esc("aaa")); assertThat(process("%{%{%{%{%{%{%{%{%{%{!}%}%}%}%}%}%}%}%}%}%")) .isEqualTo(esc2(esc2(esc2(esc2(esc2("!")))))); }
@Test public void testUrlEncodingBad() { assertThat(process("bad!}%")).isEqualTo("bad!}%"); assertThat(process("bad!}%%{+}%")).isEqualTo("bad!}%" + esc("+")); assertThat(process("bad!%{")).isEqualTo("bad!"); assertThat(process("%{bad!")).isEqualTo("bad!"); assertThat(process("%{good!}%{bad!}%")).isEqualTo(esc("good!") + "{bad!}%"); }