@Test
@SuppressWarnings("unchecked")
public void testWithClassLoader() {

    // Create parameters map
    final Map<String, String> parameters = (Map<String, String>) Map$.MODULE$.<String, String>newBuilder()
        .$plus$eq(new Tuple2<>("dbtable", "mytable"))
        .$plus$eq(new Tuple2<>("url", "jdbc:h2:mem:spark"))
        .result();
    // Test creating a JDBC relation
    final DataSourceResourceLoader classLoader = new DataSourceResourceLoader(Mockito.mock(SparkContext.class), Thread.currentThread().getContextClassLoader());
    final AtomicReference<JdbcRelation> relation = new AtomicReference<>();
    classLoader.runWithThreadContext(new Runnable() {
        @Override
        public void run() {
            try (final Connection conn = DriverManager.getConnection("jdbc:h2:mem:spark"); final Statement stmt = conn.createStatement()) {
                stmt.execute("CREATE TABLE mytable (col1 VARCHAR)");
                final JdbcRelationProvider provider = new JdbcRelationProvider();
                relation.set((JdbcRelation) provider.createRelation(Mockito.mock(SQLContext.class), parameters));
            } catch (final Exception e) {
                Throwables.propagate(e);
            }
        }
    });
    Assert.assertNotNull("Expected relation to be created", relation.get());
    Assert.assertEquals(JDBCRelation.class, relation.get().getDelegate().getClass());
    Assert.assertEquals(classLoader, relation.get().getLoader());
}