PlatformKettleDataSourceProvider implements DataSourceProviderInterface { @Override public DataSource invalidateNamedDataSource( String datasourceName, DatasourceType type ) throws DataSourceNamingException { IDBDatasourceService service; switch ( type ) { case JNDI: service = getService( IJndiDatasourceService.class ); break; case POOLED: service = getService( IPooledDatasourceService.class ); break; default: service = getService( IDBDatasourceService.class ); } if ( service != null ) { try { DataSource dataSource = service.getDataSource( datasourceName ); if ( dataSource == null ) { return null; } service.clearDataSource( datasourceName ); return dataSource; } catch ( DBDatasourceServiceException ex ) { throw new DataSourceNamingException( ex ); } } return null; } private  PlatformKettleDataSourceProvider(); DataSourceProviderInterface getInstance(); DataSource getNamedDataSource( String dataSourceName ); @Override DataSource getNamedDataSource( String dataSourceName, DataSourceProviderInterface.DatasourceType type ); @Override DataSource invalidateNamedDataSource( String datasourceName, DatasourceType type );  }
@Test public void testInvalidateNamedDataSource() throws Exception { DataSourceProviderInterface dsp = mock( PlatformKettleDataSourceProvider.class ); String namedDataSource = UUID.randomUUID().toString(); IPooledDatasourceService service = mock( IPooledDatasourceService.class ); DataSource dataSource = mock( DataSource.class ); doReturn( service ).when( dsp, "getService", IPooledDatasourceService.class ); when( service.getDataSource( namedDataSource ) ).thenReturn( dataSource ); when( dsp.invalidateNamedDataSource( namedDataSource, DataSourceProviderInterface.DatasourceType.POOLED ) ) .thenCallRealMethod(); dsp.invalidateNamedDataSource( namedDataSource, DataSourceProviderInterface.DatasourceType.POOLED ); Mockito.verify( service, Mockito.times( 1 ) ).clearDataSource( namedDataSource ); }