1616
1717package com .google .cloud .bigquery ;
1818
19+ import static com .google .common .truth .Truth .assertThat ;
1920import static org .easymock .EasyMock .createMock ;
2021import static org .easymock .EasyMock .createStrictMock ;
2122import static org .easymock .EasyMock .eq ;
3334import com .google .cloud .bigquery .InsertAllRequest .RowToInsert ;
3435import com .google .common .collect .ImmutableList ;
3536import com .google .common .collect .ImmutableMap ;
36- import com .google .common .collect .Iterators ;
37- import java .util .Iterator ;
3837import java .util .List ;
3938import org .junit .After ;
4039import org .junit .Test ;
@@ -58,9 +57,9 @@ public class TableTest {
5857 JobInfo .of (LoadJobConfiguration .of (TABLE_ID1 , ImmutableList .of ("URI" ), FormatOptions .json ()));
5958 private static final JobInfo EXTRACT_JOB_INFO =
6059 JobInfo .of (ExtractJobConfiguration .of (TABLE_ID1 , ImmutableList .of ("URI" ), "CSV" ));
61- private static final Field FIELD = Field .of ("FieldName" , LegacySQLTypeName .INTEGER );
62- private static final TableDefinition TABLE_DEFINITION =
63- StandardTableDefinition .of (Schema . of ( FIELD ) );
60+ private static final Field FIELD = Field .of ("FieldName" , LegacySQLTypeName .STRING );
61+ private static final Schema SCHEMA = Schema . of ( FIELD );
62+ private static final TableDefinition TABLE_DEFINITION = StandardTableDefinition .of (SCHEMA );
6463 private static final TableInfo TABLE_INFO = TableInfo .of (TABLE_ID1 , TABLE_DEFINITION );
6564 private static final List <RowToInsert > ROWS_TO_INSERT = ImmutableList .of (
6665 RowToInsert .of ("id1" , ImmutableMap .<String , Object >of ("key" , "val1" )),
@@ -82,6 +81,10 @@ public class TableTest {
8281 ImmutableList .of (
8382 FieldValueList .of (ImmutableList .of (FIELD_VALUE1 )),
8483 FieldValueList .of (ImmutableList .of (FIELD_VALUE2 )));
84+ private static final List <FieldValueList > ROWS_WITH_SCHEMA =
85+ ImmutableList .of (
86+ FieldValueList .of (ImmutableList .of (FIELD_VALUE1 )).withSchema (SCHEMA .getFields ()),
87+ FieldValueList .of (ImmutableList .of (FIELD_VALUE2 )).withSchema (SCHEMA .getFields ()));
8588 private BigQuery serviceMockReturnsOptions = createStrictMock (BigQuery .class );
8689 private BigQueryOptions mockOptions = createMock (BigQueryOptions .class );
8790 private BigQuery bigquery ;
@@ -269,31 +272,38 @@ public void testInsertComplete() throws Exception {
269272
270273 @ Test
271274 public void testList () throws Exception {
275+ Page <FieldValueList > page = new PageImpl <>(null , "c" , ROWS );
276+
272277 initializeExpectedTable (1 );
273278 expect (bigquery .getOptions ()).andReturn (mockOptions );
274- TableResult tableDataPage = new TableResult (null , ROWS .size (), new PageImpl <>(null , "c" , ROWS ));
275- expect (bigquery .listTableData (TABLE_ID1 )).andReturn (tableDataPage );
279+ expect (bigquery .listTableData (TABLE_ID1 )).andReturn (new TableResult (null , ROWS .size (), page ));
280+ expect (bigquery .listTableData (TABLE_ID1 , SCHEMA ))
281+ .andReturn (new TableResult (SCHEMA , ROWS .size (), page ));
276282 replay (bigquery );
277283 initializeTable ();
278284 Page <FieldValueList > dataPage = table .list ();
279- Iterator <FieldValueList > tableDataIterator = dataPage .getValues ().iterator ();
280- Iterator <FieldValueList > dataIterator = dataPage .getValues ().iterator ();
281- assertTrue (Iterators .elementsEqual (tableDataIterator , dataIterator ));
285+ assertThat (dataPage .getValues ()).containsExactlyElementsIn (ROWS ).inOrder ();
286+
287+ dataPage = table .list (SCHEMA );
288+ assertThat (dataPage .getValues ()).containsExactlyElementsIn (ROWS_WITH_SCHEMA ).inOrder ();
282289 }
283290
284291 @ Test
285292 public void testListWithOptions () throws Exception {
293+ Page <FieldValueList > page = new PageImpl <>(null , "c" , ROWS );
286294 initializeExpectedTable (1 );
287295 expect (bigquery .getOptions ()).andReturn (mockOptions );
288- TableResult tableDataPage = new TableResult (null , ROWS .size (), new PageImpl <>(null , "c" , ROWS ));
289296 expect (bigquery .listTableData (TABLE_ID1 , BigQuery .TableDataListOption .pageSize (10L )))
290- .andReturn (tableDataPage );
297+ .andReturn (new TableResult (null , ROWS .size (), page ));
298+ expect (bigquery .listTableData (TABLE_ID1 , SCHEMA , BigQuery .TableDataListOption .pageSize (10L )))
299+ .andReturn (new TableResult (SCHEMA , ROWS .size (), page ));
291300 replay (bigquery );
292301 initializeTable ();
293302 Page <FieldValueList > dataPage = table .list (BigQuery .TableDataListOption .pageSize (10L ));
294- Iterator <FieldValueList > tableDataIterator = dataPage .getValues ().iterator ();
295- Iterator <FieldValueList > dataIterator = dataPage .getValues ().iterator ();
296- assertTrue (Iterators .elementsEqual (tableDataIterator , dataIterator ));
303+ assertThat (dataPage .getValues ()).containsExactlyElementsIn (ROWS ).inOrder ();
304+
305+ dataPage = table .list (SCHEMA , BigQuery .TableDataListOption .pageSize (10L ));
306+ assertThat (dataPage .getValues ()).containsExactlyElementsIn (ROWS_WITH_SCHEMA ).inOrder ();
297307 }
298308
299309 @ Test
0 commit comments