package com.zaxxer.hikari;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.junit.Assert;
import org.junit.Test;

public class ExceptionTest
{
    @Test
    public void testException1() throws SQLException
    {
        HikariConfig config = new HikariConfig();
        config.setMinimumPoolSize(1);
        config.setMaximumPoolSize(2);
        config.setAcquireIncrement(1);
        config.setConnectionTestQuery("VALUES 1");
        config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");

        HikariDataSource ds = new HikariDataSource(config);

        Assert.assertSame("Totals connections not as expected", 1, ds.pool.getTotalConnections());
        Assert.assertSame("Idle connections not as expected", 1, ds.pool.getIdleConnections());

        Connection connection = ds.getConnection();
        Assert.assertNotNull(connection);

        Assert.assertSame("Totals connections not as expected", 1, ds.pool.getTotalConnections());
        Assert.assertSame("Idle connections not as expected", 0, ds.pool.getIdleConnections());

        PreparedStatement statement = connection.prepareStatement("SELECT some, thing FROM somewhere WHERE something=?");
        Assert.assertNotNull(statement);

        ResultSet resultSet = statement.executeQuery();
        Assert.assertNotNull(resultSet);

        try
        {
            resultSet.getFloat(1);
            Assert.fail();
        }
        catch (Exception e)
        {
            Assert.assertSame(SQLException.class, e.getClass());
        }

        connection.close();

        Assert.assertSame("Totals connections not as expected", 0, ds.pool.getTotalConnections());
        Assert.assertSame("Idle connections not as expected", 0, ds.pool.getIdleConnections());
    }
}

@@ -1834,11 +1834,1438 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testUseAfterClose() throws SQLException%0A    %7B%0A        HikariConfig config = new HikariConfig();%0A        config.setMinimumPoolSize(1);%0A        config.setMaximumPoolSize(2);%0A        config.setAcquireIncrement(1);%0A        config.setConnectionTestQuery(%22VALUES 1%22);%0A        config.setDataSourceClassName(%22com.zaxxer.hikari.mocks.StubDataSource%22);%0A%0A        HikariDataSource ds = new HikariDataSource(config);%0A%0A        Assert.assertSame(%22Totals connections not as expected%22, 1, ds.pool.getTotalConnections());%0A        Assert.assertSame(%22Idle connections not as expected%22, 1, ds.pool.getIdleConnections());%0A%0A        Connection connection = ds.getConnection();%0A        Assert.assertNotNull(connection);%0A%0A        Assert.assertSame(%22Totals connections not as expected%22, 1, ds.pool.getTotalConnections());%0A        Assert.assertSame(%22Idle connections not as expected%22, 0, ds.pool.getIdleConnections());%0A%0A        connection.close();%0A%0A        try%0A        %7B%0A            connection.prepareStatement(%22SELECT some, thing FROM somewhere WHERE something=?%22);%0A            Assert.fail();%0A        %7D%0A        catch (SQLException e)%0A        %7B%0A            Assert.assertSame(%22Connection is closed%22, e.getMessage());%0A        %7D%0A%0A        Assert.assertSame(%22Totals connections not as expected%22, 1, ds.pool.getTotalConnections());%0A        Assert.assertSame(%22Idle connections not as expected%22, 1, ds.pool.getIdleConnections());%0A    %7D
 %0A%7D%0A

Add test for connection use after close().