mirror of
https://github.com/google/nomulus.git
synced 2025-07-12 05:58:13 +02:00
Consolidate EntityManagerFactoryProviderTest (#253)
Check if EntityManagerFactory is null before calling close() to avoid NullPointerException.
This commit is contained in:
parent
28700cd610
commit
2967256766
2 changed files with 10 additions and 2 deletions
|
@ -14,6 +14,7 @@
|
|||
|
||||
package google.registry.persistence;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static google.registry.config.RegistryConfig.getHibernateConnectionIsolation;
|
||||
import static google.registry.config.RegistryConfig.getHibernateHikariConnectionTimeout;
|
||||
import static google.registry.config.RegistryConfig.getHibernateHikariIdleTimeout;
|
||||
|
@ -62,6 +63,11 @@ public class EntityManagerFactoryProvider {
|
|||
properties.put(Environment.URL, jdbcUrl);
|
||||
properties.put(Environment.USER, username);
|
||||
properties.put(Environment.PASS, password);
|
||||
return Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties.build());
|
||||
EntityManagerFactory emf =
|
||||
Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties.build());
|
||||
checkState(
|
||||
emf != null,
|
||||
"Persistence.createEntityManagerFactory() returns a null EntityManagerFactory");
|
||||
return emf;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,9 @@ public class EntityManagerFactoryProviderTest {
|
|||
|
||||
@After
|
||||
public void destroy() {
|
||||
if (emf != null) {
|
||||
emf.close();
|
||||
}
|
||||
emf = null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue