DefaultPersistenceProviderResolver implements PersistenceProviderResolver { @Override public synchronized List<PersistenceProvider> getPersistenceProviders() { if (providers == null) { this.providers = initProviders(); } return Collections.unmodifiableList(providers); }  @Override synchronized List<PersistenceProvider> getPersistenceProviders(); @Override synchronized void clearCachedProviders(); static synchronized void registerPersistenceProviderClass(Class<? extends PersistenceProvider> cls); static final String PROVIDER_FILE; }
@Test void getProvidersReturnsProvidersFoundOnClasspathViaMetaInfConfiguration() throws Exception { generateProviderFileContent("cz.cvut.kbss.jopa.environment.TestPersistenceProvider"); final List<PersistenceProvider> result = resolver.getPersistenceProviders(); assertFalse(result.isEmpty()); final Optional<PersistenceProvider> pp = result.stream().filter(p -> p instanceof TestPersistenceProvider) .findAny(); assertTrue(pp.isPresent()); }
@Test void registerProviderClassSkipsClassesConfiguredOnClasspathButNotFound() throws Exception { generateProviderFileContent("cz.cvut.kbss.jopa.UnknownClass"); final List<PersistenceProvider> result = resolver.getPersistenceProviders(); assertNotNull(result); }
@Test void registerProviderClassSkipsClassConfiguredOnClasspathAndNotPersistenceProviderImplementation() throws Exception { generateProviderFileContent(DefaultPersistenceProviderResolver.class.getName()); final List<PersistenceProvider> result = resolver.getPersistenceProviders(); assertNotNull(result); result.forEach(r -> assertFalse(r instanceof DefaultPersistenceProviderResolver)); }