### Question:
QueryPreparer { public PreparedQuery prepareQuery(Session session, String query) throws ParsingException, PrestoException { Statement wrappedStatement = sqlParser.createStatement(query, createParsingOptions(session)); return prepareQuery(session, wrappedStatement); } @Inject  QueryPreparer(SqlParser sqlParser); PreparedQuery prepareQuery(Session session, String query); PreparedQuery prepareQuery(Session session, Statement wrappedStatement);  }### Answer:
@Test public void testSelectStatement() { PreparedQuery preparedQuery = QUERY_PREPARER.prepareQuery(TEST_SESSION, "SELECT * FROM foo"); assertEquals(preparedQuery.getStatement(), simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("foo")))); }
@Test public void testExecuteStatement() { Session session = testSessionBuilder() .addPreparedStatement("my_query", "SELECT * FROM foo") .build(); PreparedQuery preparedQuery = QUERY_PREPARER.prepareQuery(session, "EXECUTE my_query"); assertEquals(preparedQuery.getStatement(), simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("foo")))); }
@Test public void testExecuteStatementDoesNotExist() { assertPrestoExceptionThrownBy(() -> QUERY_PREPARER.prepareQuery(TEST_SESSION, "execute my_query")) .hasErrorCode(NOT_FOUND); }
@Test public void testTooManyParameters() { Session session = testSessionBuilder() .addPreparedStatement("my_query", "SELECT * FROM foo where col1 = ?") .build(); assertPrestoExceptionThrownBy(() -> QUERY_PREPARER.prepareQuery(session, "EXECUTE my_query USING 1,2")) .hasErrorCode(INVALID_PARAMETER_USAGE); }
@Test public void testTooFewParameters() { Session session = testSessionBuilder() .addPreparedStatement("my_query", "SELECT ? FROM foo where col1 = ?") .build(); assertPrestoExceptionThrownBy(() -> QUERY_PREPARER.prepareQuery(session, "EXECUTE my_query USING 1")) .hasErrorCode(INVALID_PARAMETER_USAGE); }
@Test public void testParameterMismatchWithOffset() { Session session = testSessionBuilder() .addPreparedStatement("my_query", "SELECT ? FROM foo OFFSET ? ROWS") .build(); assertPrestoExceptionThrownBy(() -> QUERY_PREPARER.prepareQuery(session, "EXECUTE my_query USING 1")) .hasErrorCode(INVALID_PARAMETER_USAGE); assertPrestoExceptionThrownBy(() -> QUERY_PREPARER.prepareQuery(session, "EXECUTE my_query USING 1, 2, 3, 4, 5, 6")) .hasErrorCode(INVALID_PARAMETER_USAGE); }
@Test public void testParameterMismatchWithLimit() { Session session = testSessionBuilder() .addPreparedStatement("my_query", "SELECT ? FROM foo LIMIT ?") .build(); assertPrestoExceptionThrownBy(() -> QUERY_PREPARER.prepareQuery(session, "EXECUTE my_query USING 1")) .hasErrorCode(INVALID_PARAMETER_USAGE); assertPrestoExceptionThrownBy(() -> QUERY_PREPARER.prepareQuery(session, "EXECUTE my_query USING 1, 2, 3, 4, 5, 6")) .hasErrorCode(INVALID_PARAMETER_USAGE); }
@Test public void testParameterMismatchWithFetchFirst() { Session session = testSessionBuilder() .addPreparedStatement("my_query", "SELECT ? FROM foo FETCH FIRST ? ROWS ONLY") .build(); assertPrestoExceptionThrownBy(() -> QUERY_PREPARER.prepareQuery(session, "EXECUTE my_query USING 1")) .hasErrorCode(INVALID_PARAMETER_USAGE); assertPrestoExceptionThrownBy(() -> QUERY_PREPARER.prepareQuery(session, "EXECUTE my_query USING 1, 2, 3, 4, 5, 6")) .hasErrorCode(INVALID_PARAMETER_USAGE); }