88
99import org .hibernate .SessionFactory ;
1010import org .hibernate .boot .MetadataSources ;
11- import org .hibernate .boot .registry .StandardServiceRegistry ;
12- import org .hibernate .boot .registry .StandardServiceRegistryBuilder ;
1311import org .hibernate .boot .spi .SessionFactoryBuilderImplementor ;
1412import org .hibernate .cfg .AvailableSettings ;
1513
1614import org .hibernate .testing .orm .junit .JiraKey ;
17- import org .hibernate .testing .junit4 .BaseUnitTestCase ;
18- import org .hibernate .testing .util .ServiceRegistryUtil ;
19- import org .junit .Test ;
15+ import org .hibernate .testing .orm .junit .ServiceRegistry ;
16+ import org .hibernate .testing .orm .junit .ServiceRegistryScope ;
17+ import org .hibernate .testing .orm .junit .Setting ;
18+ import org .junit .jupiter .api .Test ;
2019
21- import static org .junit .Assert .assertTrue ;
22- import static org .junit .Assert .fail ;
20+ import static org .junit .jupiter . api . Assertions .assertTrue ;
21+ import static org .junit .jupiter . api . Assertions .fail ;
2322
2423/**
2524 * @author Steve Ebersole
2625 */
2726@ JiraKey ( value = "12097" )
28- public class ClosedFactoryTests extends BaseUnitTestCase {
27+ @ ServiceRegistry (settings = {@ Setting (name = AvailableSettings .JPA_CLOSED_COMPLIANCE , value = "true" )})
28+ public class ClosedFactoryTests {
2929 @ Test
30- public void testClosedChecks () {
31- final StandardServiceRegistry ssr = ServiceRegistryUtil .serviceRegistryBuilder ()
32- .applySetting ( AvailableSettings .JPA_CLOSED_COMPLIANCE , "true" )
33- .build ();
30+ public void testClosedChecks (ServiceRegistryScope scope ) {
3431
35- try {
36- final SessionFactoryBuilderImplementor factoryBuilder = (SessionFactoryBuilderImplementor ) new MetadataSources ( ssr )
32+ final SessionFactoryBuilderImplementor factoryBuilder = (SessionFactoryBuilderImplementor ) new MetadataSources ( scope .getRegistry () )
3733 .buildMetadata ()
3834 .getSessionFactoryBuilder ();
3935 final SessionFactory sf = factoryBuilder .build ();
@@ -52,7 +48,7 @@ public void testClosedChecks() {
5248 // this is the expected outcome
5349 }
5450 catch (Exception e ) {
55- fail ( "#getCache failed, but not with the expected IllegalStateException : " + e . toString () );
51+ fail ( "#getCache failed, but not with the expected IllegalStateException : " + e );
5652 }
5753
5854 try {
@@ -63,7 +59,7 @@ public void testClosedChecks() {
6359 // this is the expected outcome
6460 }
6561 catch (Exception e ) {
66- fail ( "#getMetamodel failed, but not with the expected IllegalStateException : " + e . toString () );
62+ fail ( "#getMetamodel failed, but not with the expected IllegalStateException : " + e );
6763 }
6864
6965 try {
@@ -74,7 +70,7 @@ public void testClosedChecks() {
7470 // this is the expected outcome
7571 }
7672 catch (Exception e ) {
77- fail ( "#getCriteriaBuilder failed, but not with the expected IllegalStateException : " + e . toString () );
73+ fail ( "#getCriteriaBuilder failed, but not with the expected IllegalStateException : " + e );
7874 }
7975
8076 try {
@@ -85,7 +81,7 @@ public void testClosedChecks() {
8581 // this is the expected outcome
8682 }
8783 catch (Exception e ) {
88- fail ( "#getProperties failed, but not with the expected IllegalStateException : " + e . toString () );
84+ fail ( "#getProperties failed, but not with the expected IllegalStateException : " + e );
8985 }
9086
9187 try {
@@ -96,7 +92,7 @@ public void testClosedChecks() {
9692 // this is the expected outcome
9793 }
9894 catch (Exception e ) {
99- fail ( "#getPersistenceUnitUtil failed, but not with the expected IllegalStateException : " + e . toString () );
95+ fail ( "#getPersistenceUnitUtil failed, but not with the expected IllegalStateException : " + e );
10096 }
10197
10298 try {
@@ -107,7 +103,7 @@ public void testClosedChecks() {
107103 // this is the expected outcome
108104 }
109105 catch (Exception e ) {
110- fail ( "#close failed, but not with the expected IllegalStateException : " + e . toString () );
106+ fail ( "#close failed, but not with the expected IllegalStateException : " + e );
111107 }
112108
113109 try {
@@ -118,7 +114,7 @@ public void testClosedChecks() {
118114 // this is the expected outcome
119115 }
120116 catch (Exception e ) {
121- fail ( "#createEntityManager failed, but not with the expected IllegalStateException : " + e . toString () );
117+ fail ( "#createEntityManager failed, but not with the expected IllegalStateException : " + e );
122118 }
123119
124120 try {
@@ -129,12 +125,7 @@ public void testClosedChecks() {
129125 // this is the expected outcome
130126 }
131127 catch (Exception e ) {
132- fail ( "#createEntityManager(Map) failed, but not with the expected IllegalStateException : " + e . toString () );
128+ fail ( "#createEntityManager(Map) failed, but not with the expected IllegalStateException : " + e );
133129 }
134- }
135- catch (Exception e ) {
136- // if an exception is
137- StandardServiceRegistryBuilder .destroy ( ssr );
138- }
139130 }
140131}
0 commit comments