QueryStatement implements IPreparedQuery { public PreparedStatement compile(final Connection connection) throws SQLException { PreparedStatement stmt = connection.prepareStatement(this.bodyWriter.toString()); int index = 1; for (SQLQueryParameterSetter setter : this.parameterSetters) { index = setter.setParameters(stmt, index); } return stmt; } QueryStatement(); Writer getBodyWriter(); void pushParameterSetter(final SQLQueryParameterSetter setter); PreparedStatement compile(final Connection connection);  }
@Test public void MustCorrectCompileQuery() throws SQLException { Connection connection = mock(Connection.class); PreparedStatement preparedStatement = mock(PreparedStatement.class); String bodyWriterStringPresent = "asdadsad"; when(bodyWriter.toString()).thenReturn(bodyWriterStringPresent); when(connection.prepareStatement(bodyWriterStringPresent)).thenReturn(preparedStatement); int index = 1; for (SQLQueryParameterSetter setter : parameterSetters) { when(setter.setParameters(preparedStatement, index)).thenReturn(index); } assertTrue(testQueryStatement.compile(connection) == preparedStatement); verify(connection).prepareStatement(bodyWriterStringPresent); for (SQLQueryParameterSetter setter : parameterSetters) { verify(setter).setParameters(preparedStatement, index); } }