@Test
public void testCreateConnection() throws SQLException {

  PentahoJndiDatasourceConnectionProvider jndicp = Mockito.mock( PentahoJndiDatasourceConnectionProvider.class );
  PentahoPoolDataSourceConnectionProvider poolcp = Mockito.mock( PentahoPoolDataSourceConnectionProvider.class );
  PentahoPmdConnectionProvider ppcp = Mockito.spy( new PentahoPmdConnectionProvider() );
  when( ppcp.getJndiProvider() ).thenReturn( jndicp );
  when( ppcp.getPoolProvider() ).thenReturn( poolcp );
  when( jndicp.createConnection( any(), any() ) ).thenReturn( (Connection) Mockito.mock( Connection.class ) );
  when( poolcp.createConnection( any(), any() ) ).thenReturn( (Connection) Mockito.mock( Connection.class ) );
  String username = "user";
  String password = "pass";
  DatabaseMeta databaseMeta = mock( DatabaseMeta.class );
  when( databaseMeta.getAccessType() ).thenReturn( DatabaseMeta.TYPE_ACCESS_JNDI );
  when( databaseMeta.getDatabaseName() ).thenReturn( "test" );
  when( databaseMeta.isUsingConnectionPool() ).thenReturn( false );
  try {
    Connection conn = ppcp.createConnection( databaseMeta, username, password  );
    Assert.assertFalse( "JNDI connection", conn == null );
  } catch ( ReportDataFactoryException e ) {
    Assert.fail();
  }
  when( databaseMeta.getAccessType() ).thenReturn( DatabaseMeta.TYPE_ACCESS_NATIVE );
  when( databaseMeta.getName() ).thenReturn( "test" );
  when( databaseMeta.isUsingConnectionPool() ).thenReturn( true );
  try {
    Connection conn = ppcp.createConnection( databaseMeta, username, password  );
    Assert.assertFalse( "Pool connection", conn == null );
  } catch ( ReportDataFactoryException e ) {
    Assert.fail();
  }
}