### Question:
AbstractJdbcDataSetProvider implements DataSetProvider<T> { @Override public final void write(@Nonnull final KyloCatalogClient<T> client, @Nonnull final DataSetOptions options, @Nonnull final T dataSet) { final String url = DataSetUtil.getOptionOrThrow(options, "url", "Option 'url' is required"); final String table = DataSetUtil.getOptionOrThrow(options, "dbtable", "Option 'dbtable' is required"); final Properties properties = new Properties(); properties.putAll(options.getOptions()); final DataFrameWriter writer = SparkUtil.prepareDataFrameWriter(getDataFrameWriter(dataSet, options), options, null); writer.jdbc(url, table, properties); }  @Override boolean supportsFormat(@Nonnull final String source); @Nonnull @Override final T read(@Nonnull final KyloCatalogClient<T> client, @Nonnull final DataSetOptions options); @Override final void write(@Nonnull final KyloCatalogClient<T> client, @Nonnull final DataSetOptions options, @Nonnull final T dataSet);  }### Answer:
@Test public void write() throws Exception { final DataFrame dataFrame = Mockito.mock(DataFrame.class); final SQLContext sqlContext = Mockito.mock(SQLContext.class); Mockito.when(sqlContext.conf()).thenReturn(new SQLConf()); Mockito.when(dataFrame.sqlContext()).thenReturn(sqlContext); final StructField field1 = DataTypes.createStructField("col1", DataTypes.IntegerType, true); final StructField field2 = DataTypes.createStructField("col2", DataTypes.StringType, true); Mockito.when(dataFrame.schema()).thenReturn(DataTypes.createStructType(Arrays.asList(field1, field2))); final DataSetOptions options = new DataSetOptions(); options.setOption("dbtable", "mytable"); options.setOption("url", "jdbc:h2:mem:spark"); try (final Connection conn = DriverManager.getConnection("jdbc:h2:mem:spark")) { final MockJdbcDataSetProvider provider = new MockJdbcDataSetProvider(); provider.write(Mockito.mock(KyloCatalogClient.class), options, dataFrame); try (final Statement stmt = conn.createStatement(); final ResultSet rs = stmt.executeQuery("SHOW COLUMNS FROM mytable")) { Assert.assertTrue("Expected 2 rows; found 0 rows", rs.next()); Assert.assertEquals("COL1", rs.getString(1)); Assert.assertEquals("INTEGER(10)", rs.getString(2)); Assert.assertTrue("Expected 2 rows; found 1 row", rs.next()); Assert.assertEquals("COL2", rs.getString(1)); Assert.assertEquals("CLOB(2147483647)", rs.getString(2)); Assert.assertFalse("Expected 2 rows; fonud 3 rows", rs.next()); } } }
@Test(expected = MissingOptionException.class) public void writeWithoutDbtable() { final DataSetOptions options = new DataSetOptions(); options.setOption("url", "jdbc:h2:mem:"); final MockJdbcDataSetProvider provider = new MockJdbcDataSetProvider(); provider.write(Mockito.mock(KyloCatalogClient.class), options, Mockito.mock(DataFrame.class)); }
@Test(expected = MissingOptionException.class) public void writeWithoutUrl() { final DataSetOptions options = new DataSetOptions(); options.setOption("dbtable", "mytable"); final MockJdbcDataSetProvider provider = new MockJdbcDataSetProvider(); provider.write(Mockito.mock(KyloCatalogClient.class), options, Mockito.mock(DataFrame.class)); }