PooledDataSourceFactory implements Supplier<PooledDataSource> { @Override public PooledDataSource get() { logger.trace("Extracting PooledDataSource from hibernate session " + "factory."); SessionFactoryServiceRegistryImpl src = (SessionFactoryServiceRegistryImpl) sessionFactory.getServiceRegistry(); ConnectionProvider cp = src.getService(ConnectionProvider.class); return cp.unwrap(PooledDataSource.class); } @Inject  PooledDataSourceFactory(final SessionFactory sessionFactory); @Override PooledDataSource get();  }
@Test public void testProvide() { PooledDataSourceFactory factory = new PooledDataSourceFactory(getSessionFactory()); PooledDataSource ds = factory.get(); assertNotNull(ds); assertTrue(ds instanceof PoolBackedDataSource); }
@Test public void testBinder() { Binder b = new PooledDataSourceFactory.Binder(); List<Binding> bindings = new ArrayList<>(b.getBindings()); assertEquals(1, bindings.size()); Binding binding = bindings.get(0); Set types = binding.getContracts(); assertTrue(types.contains(PooledDataSource.class)); }