package org.factcast.store.pgsql.internal.listen;

import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.mockito.MockitoAnnotations.*;

import java.util.Properties;

import javax.sql.DataSource;

import org.apache.tomcat.jdbc.pool.PoolConfiguration;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;

@SuppressWarnings("all")
public class PGDriverManagerConnectionSupplier0Test {

    PGDriverManagerConnectionSupplier uut;

    @Mock
    private org.apache.tomcat.jdbc.pool.DataSource ds;

    @Before
    public void prepare() {

        initMocks(this);
        uut = new PGDriverManagerConnectionSupplier(ds);
    }

    @Test(expected = IllegalStateException.class)
    public void test_wrongDataSourceImplementation() {

        DataSource ds = mock(DataSource.class);
        new PGDriverManagerConnectionSupplier(ds);

        failBecauseExceptionWasNotThrown(IllegalStateException.class);
    }

    @Test
    public void test_buildCredentials() {

        // given
        PoolConfiguration poolConf = mock(PoolConfiguration.class);
        when(poolConf.getPassword()).thenReturn("testPassword");
        when(poolConf.getUsername()).thenReturn("testUsername");
        when(ds.getPoolProperties()).thenReturn(poolConf);

        // when
        Properties creds = uut.buildCredentialProperties(ds);

        // then
        assertEquals("testUsername", creds.get("user"));
        assertEquals("testPassword", creds.get("password"));
    }

    @SuppressWarnings("unused")
    @Test(expected = NullPointerException.class)
    public void test_constructor() {

        new PGDriverManagerConnectionSupplier(null);

        failBecauseExceptionWasNotThrown(NullPointerException.class);

    }
}
@@ -213,16 +213,46 @@
 ons.*;%0A%0A
+import java.sql.SQLException;%0A
 import j
@@ -1587,40 +1587,8 @@
  %7D%0A%0A
-    @SuppressWarnings(%22unused%22)%0A
     
@@ -1624,32 +1624,32 @@
 xception.class)%0A
+
     public void 
@@ -1800,10 +1800,409 @@
 ;%0A%0A    %7D
+%0A%0A    @Test(expected = SQLException.class)%0A    public void testExceptionOnDriverManager_getConnection() throws Exception %7B%0A        String url = %22jdbc:xyz:foo%22;%0A        org.apache.tomcat.jdbc.pool.DataSource ds = new org.apache.tomcat.jdbc.pool.DataSource();%0A        ds.setUrl(url);%0A%0A        PGDriverManagerConnectionSupplier uut = new PGDriverManagerConnectionSupplier(ds);%0A%0A        uut.get();%0A    %7D
 %0A%7D

add coverage