BigQueryStrings { public static String toString(TableReference tableRef) { Preconditions.checkArgument(!Strings.isNullOrEmpty(tableRef.getDatasetId()), "tableRef must contain non-empty DatasetId."); Preconditions.checkArgument(!Strings.isNullOrEmpty(tableRef.getTableId()), "tableRef must contain non-empty TableId."); if (Strings.isNullOrEmpty(tableRef.getProjectId())) { return String.format("%s.%s", tableRef.getDatasetId(), tableRef.getTableId()); } else { return String.format("%s:%s.%s", tableRef.getProjectId(), tableRef.getDatasetId(), tableRef.getTableId()); } }  static String toString(TableReference tableRef); static TableReference parseTableReference(String tableRefString); static final String DATASET_AND_TABLE_REGEX; }
@Test public void testTableReferenceToStringWithNoProjectId() { TableReference tableRef = new TableReference() .setDatasetId("foo") .setTableId("bar"); assertThat(BigQueryStrings.toString(tableRef)).isEqualTo("foo.bar"); tableRef.setProjectId(""); assertThat(BigQueryStrings.toString(tableRef)).isEqualTo("foo.bar"); }
@Test public void testTableReferenceToStringWithProjectId() { TableReference tableRef = new TableReference() .setProjectId("foo-proj") .setDatasetId("foo") .setTableId("bar"); assertThat(BigQueryStrings.toString(tableRef)).isEqualTo("foo-proj:foo.bar"); }
@Test public void testToStringThrowsWhenTableIdIsNull() { TableReference tableRef = new TableReference() .setProjectId("foo-proj") .setDatasetId("foo") .setTableId(null); assertThrows(IllegalArgumentException.class, () -> BigQueryStrings.toString(tableRef)); }
@Test public void testToStringThrowsWhenTableIdIsEmpty() { TableReference tableRef = new TableReference() .setProjectId("foo-proj") .setDatasetId("foo") .setTableId(""); assertThrows(IllegalArgumentException.class, () -> BigQueryStrings.toString(tableRef)); }
@Test public void testToStringThrowsWhenDatasetIsNull() { TableReference tableRef = new TableReference() .setProjectId("foo-proj") .setDatasetId(null) .setTableId("tableId"); assertThrows(IllegalArgumentException.class, () -> BigQueryStrings.toString(tableRef)); }
@Test public void testToStringThrowsWhenDatasetIsEmpty() { TableReference tableRef = new TableReference() .setProjectId("foo-proj") .setDatasetId("") .setTableId("tableId"); assertThrows(IllegalArgumentException.class, () -> BigQueryStrings.toString(tableRef)); }