/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jdbi.v3.sqlite3;

import org.assertj.core.api.Assertions;
import org.jdbi.v3.core.Handle;
import org.jdbi.v3.core.HandleConsumer;
import org.jdbi.v3.core.Jdbi;
import org.jdbi.v3.sqlite3.SQLitePlugin;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;

public class TestUrls {

    Handle handle;

    @Before
    public void setUp() throws Exception {
        Jdbi jdbi = Jdbi.create("jdbc:sqlite::memory:");
        jdbi.installPlugin(new SQLitePlugin());
        handle = jdbi.open();
        handle.useTransaction(handle -> handle.execute("CREATE TABLE foo(url URL);"));
    }

    @After
    public void tearDown() throws Exception {
        handle.close();
    }

    @Test
    public void testInsertUrlSuccessful() throws MalformedURLException {
        String goolgeString = "http://www.google.com";
        URL googleUrl = new URL(goolgeString);

        handle.createUpdate("INSERT INTO foo VALUES (:url)")
                .bind("url", googleUrl)
                .execute();

        URL actualUrl = handle.createQuery("SELECT * FROM foo").mapTo(URL.class).findOnly();
        Assertions.assertThat(actualUrl).hasToString(googleUrl.toString());
    }

}

@@ -723,16 +723,67 @@
 e.Jdbi;%0A
+import org.jdbi.v3.core.result.ResultSetException;%0A
 import o
@@ -1754,17 +1754,19 @@
 %22SELECT 
-*
+url
  FROM fo
@@ -1881,10 +1881,787 @@
 %0A    %7D%0A%0A
+    @Test(expected = ResultSetException.class)%0A    public void testMapNullUrlThrowsException() %7B%0A        handle.createUpdate(%22INSERT INTO foo VALUES (:url)%22)%0A                .bind(%22url%22, ((URL) null))%0A                .execute();%0A%0A        handle.createQuery(%22SELECT url FROM foo%22).mapTo(URL.class).findOnly();%0A    %7D%0A%0A    @Test%0A    public void testInserUrlUsingBindByType() throws MalformedURLException %7B%0A        URL githubUrl = new URL(%22http://www.github.com%22);%0A%0A        handle.createUpdate(%22INSERT INTO foo VALUES (:url)%22)%0A                .bindByType(%22url%22, githubUrl, URL.class)%0A                .execute();%0A%0A        URL dbUrl = handle.createQuery(%22SELECT * FROM foo%22).mapTo(URL.class).findOnly();%0A        Assertions.assertThat(dbUrl).hasToString(githubUrl.toString());%0A    %7D%0A%0A
 %7D%0A

Test inserting null urls and using bindByType.