AbstractSessionHolderProviderManager implements SessionHolderProviderManager { public SessionHolderProvider getSessionProvider(Repository repository) { if (repository == null) return defaultProvider; String key = repository.getDescriptor(Repository.REP_NAME_DESC); List<SessionHolderProvider> providers = getProviders(); for (int i = 0; i < providers.size(); i++) { SessionHolderProvider provider = providers.get(i); if (provider.acceptsRepository(key)) { if (LOG.isDebugEnabled()) LOG.debug("specific SessionHolderProvider found for repository " + key); return provider; } } if (LOG.isDebugEnabled()) LOG.debug("no specific SessionHolderProvider found for repository " + key + "; using the default one"); return defaultProvider; }  abstract List<SessionHolderProvider> getProviders(); SessionHolderProvider getSessionProvider(Repository repository);  }
@Test public void testCustomSessionProvider() { providers = new ArrayList<SessionHolderProvider>(); providers.add(customProvider); replay(sessionfactory, session, repository); assertSame(customProvider, providerManager.getSessionProvider(repository)); }
@Test public void testDifferentSessionProvider() { customProvider = new SessionHolderProvider() { @Override public boolean acceptsRepository(String repo) { return false; } @Override public SessionHolder createSessionHolder(Session session) { return null; } }; providers = new ArrayList<SessionHolderProvider>(); providers.add(customProvider); replay(sessionfactory, session, repository); assertSame(GenericSessionHolderProvider.class, providerManager.getSessionProvider(repository).getClass()); }