@Test(expected = QueryResolutionException.class)
  public void throwsErrorOnParsingError() throws Exception {
    ExpressionManager expressionManager = mock(ExpressionManager.class);
    String staticSqlText = STATIC_SQL_TEXT;
    when(expressionManager.parse(DYNAMIC_SQL_TEXT, muleEvent)).thenReturn(staticSqlText);

    QueryTemplateParser queryTemplateParser = mock(QueryTemplateParser.class);
    when(queryTemplateParser.parse(staticSqlText))
        .thenThrow(new QueryTemplateParsingException("Parse error"));

    DynamicQueryResolver queryResolver =
        new DynamicQueryResolver(query, queryTemplateParser, expressionManager);

    queryResolver.resolve(null, muleEvent);
  }
  @Test
  public void resolvesDynamicQuery() throws Exception {
    ExpressionManager expressionManager = mock(ExpressionManager.class);
    String staticSqlText = STATIC_SQL_TEXT;
    when(expressionManager.parse(DYNAMIC_SQL_TEXT, muleEvent)).thenReturn(staticSqlText);

    QueryTemplate expectedQueryTemplate = createQueryTemplate(staticSqlText);
    QueryTemplateParser queryTemplateParser = mock(QueryTemplateParser.class);
    when(queryTemplateParser.parse(staticSqlText)).thenReturn(expectedQueryTemplate);

    DynamicQueryResolver queryResolver =
        new DynamicQueryResolver(query, queryTemplateParser, expressionManager);

    Query resolvedQuery = queryResolver.resolve(null, muleEvent);

    assertThat(expectedQueryTemplate, sameInstance(resolvedQuery.getQueryTemplate()));
  }