@Test
  public void testWriteAppend() throws IOException {
    onTableGet(basicTableSchema());

    TableReference ref = BigQueryIO.parseTableSpec("project:dataset.table");

    BigQueryTableInserter inserter = new BigQueryTableInserter(mockClient);

    inserter.getOrCreateTable(
        ref,
        BigQueryIO.Write.WriteDisposition.WRITE_APPEND,
        BigQueryIO.Write.CreateDisposition.CREATE_NEVER,
        null);

    verifyTableGet();
  }
  @Test
  public void testWriteEmpty() throws IOException {
    onTableGet(basicTableSchema());

    TableDataList dataList = new TableDataList().setTotalRows(0L);
    onTableList(dataList);

    TableReference ref = BigQueryIO.parseTableSpec("project:dataset.table");

    BigQueryTableInserter inserter = new BigQueryTableInserter(mockClient);

    inserter.getOrCreateTable(
        ref,
        BigQueryIO.Write.WriteDisposition.WRITE_EMPTY,
        BigQueryIO.Write.CreateDisposition.CREATE_NEVER,
        null);

    verifyTableGet();
    verifyTabledataList();
  }
  @Test
  public void testWriteEmptyFail() throws IOException {
    thrown.expect(IOException.class);

    onTableGet(basicTableSchema());

    TableDataList dataList = rawDataList(rawRow("Arthur", 42));
    onTableList(dataList);

    TableReference ref = BigQueryIO.parseTableSpec("project:dataset.table");

    BigQueryTableInserter inserter = new BigQueryTableInserter(mockClient);

    try {
      inserter.getOrCreateTable(
          ref,
          BigQueryIO.Write.WriteDisposition.WRITE_EMPTY,
          BigQueryIO.Write.CreateDisposition.CREATE_NEVER,
          null);
    } finally {
      verifyTableGet();
      verifyTabledataList();
    }
  }