@@ -258,14 +258,18 @@ public void testReadFromQueryNoTables() throws IOException, InterruptedException
258258
259259 // Mock job polling.
260260 JobStatus status = new JobStatus ().setState ("DONE" );
261- TableReference tableRef =
262- new TableReference ().setProjectId ("project" ).setDatasetId ("dataset" ).setTableId ("table" );
263- JobConfigurationQuery queryConfig = new JobConfigurationQuery ().setDestinationTable (tableRef );
261+ JobConfigurationQuery resultQueryConfig =
262+ new JobConfigurationQuery ().setDestinationTable (
263+ new TableReference ()
264+ .setProjectId ("project" )
265+ .setDatasetId ("tempdataset" )
266+ .setTableId ("temptable" )
267+ );
264268 Job getJob =
265269 new Job ()
266270 .setJobReference (new JobReference ())
267271 .setStatus (status )
268- .setConfiguration (new JobConfiguration ().setQuery (queryConfig ));
272+ .setConfiguration (new JobConfiguration ().setQuery (resultQueryConfig ));
269273 when (mockJobsGet .execute ()).thenReturn (getJob );
270274
271275 // Mock table schema fetch.
@@ -281,8 +285,9 @@ public void testReadFromQueryNoTables() throws IOException, InterruptedException
281285 String query = String .format (
282286 "SELECT \" Arthur\" as name, 42 as count, \" %s\" as photo" ,
283287 photoBytesEncoded );
288+ JobConfigurationQuery queryConfig = new JobConfigurationQuery ().setQuery (query );
284289 try (BigQueryTableRowIterator iterator =
285- BigQueryTableRowIterator .fromQuery (query , "project" , mockClient , null , null )) {
290+ BigQueryTableRowIterator .fromQuery (queryConfig , "project" , mockClient )) {
286291 iterator .open ();
287292 assertTrue (iterator .advance ());
288293 TableRow row = iterator .getCurrent ();
@@ -317,7 +322,7 @@ public void testReadFromQueryNoTables() throws IOException, InterruptedException
317322 verify (mockTablesDelete ).execute ();
318323 // Table data read.
319324 verify (mockClient ).tabledata ();
320- verify (mockTabledata ).list ("project" , "dataset " , "table " );
325+ verify (mockTabledata ).list ("project" , "tempdataset " , "temptable " );
321326 verify (mockTabledataList ).execute ();
322327 }
323328
@@ -334,18 +339,16 @@ public void testQueryFailed() throws IOException {
334339 when (mockJobsInsert .execute ()).thenThrow (exception , exception , exception , exception );
335340
336341 String query = "NOT A QUERY" ;
342+ JobConfigurationQuery queryConfig = new JobConfigurationQuery ().setQuery (query );
337343 try (BigQueryTableRowIterator iterator =
338- BigQueryTableRowIterator .fromQuery (query , "project" , mockClient , null , null )) {
339-
340- try {
341- iterator .open ();
342- fail ();
343- } catch (Exception expected ) {
344- // Verify message explains cause and reports the query.
345- assertThat (expected .getMessage (), containsString ("Error" ));
346- assertThat (expected .getMessage (), containsString (query ));
347- assertThat (expected .getCause ().getMessage (), containsString (errorReason ));
348- }
344+ BigQueryTableRowIterator .fromQuery (queryConfig , "project" , mockClient )) {
345+ iterator .open ();
346+ fail ();
347+ } catch (Exception expected ) {
348+ // Verify message explains cause and reports the query.
349+ assertThat (expected .getMessage (), containsString ("Error" ));
350+ assertThat (expected .getMessage (), containsString (query ));
351+ assertThat (expected .getCause ().getMessage (), containsString (errorReason ));
349352 }
350353
351354 // Job inserted to run the query, then polled once.
0 commit comments