@SuppressWarnings("unchecked")
  public <T extends Expression> T rewrite(final T expression, final C context) {
    return (T) rewriter.process(expression, context);
  }
@Test
  public void shouldRewriteSearchedCaseExpression() {
    // Given:
    final SearchedCaseExpression parsed = parseExpression(
        "CASE WHEN col0=1 THEN 'one' WHEN col0=2 THEN 'two' ELSE 'three' END");
    when(processor.apply(parsed.getWhenClauses().get(0), context)).thenReturn(when1);
    when(processor.apply(parsed.getWhenClauses().get(1), context)).thenReturn(when2);
    when(processor.apply(any(StringLiteral.class), any())).thenReturn(expr1);

    // When:
    final Expression rewritten = expressionRewriter.rewrite(parsed, context);

    // Then:
    assertThat(
        rewritten,
        equalTo(
            new SearchedCaseExpression(
                parsed.getLocation(),
                ImmutableList.of(when1, when2),
                Optional.of(expr1)
            )
        )
    );
  }