Skip to content

Commit 23634be

Browse files
committed
HHH-19916 - Drop JUnit 4 usage
Not converted... * org.hibernate.orm.test.type.AbstractJavaTimeTypeTest subtypes - crazy parameterization (see org.hibernate.orm.test.tm.InterceptorTransactionTest)
1 parent a28d4d4 commit 23634be

File tree

12 files changed

+495
-638
lines changed

12 files changed

+495
-638
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/boot/cfgXml/CfgXmlParsingTest.java

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,37 @@
44
*/
55
package org.hibernate.orm.test.boot.cfgXml;
66

7-
import org.hibernate.boot.registry.StandardServiceRegistry;
8-
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
97
import org.hibernate.engine.config.spi.ConfigurationService;
108
import org.hibernate.internal.util.config.ConfigurationException;
11-
12-
import org.hibernate.testing.junit4.BaseUnitTestCase;
9+
import org.hibernate.testing.orm.junit.ExpectedException;
1310
import org.hibernate.testing.util.ServiceRegistryUtil;
14-
import org.junit.Test;
15-
16-
import static org.junit.Assert.assertNotNull;
17-
import static org.junit.Assert.fail;
11+
import org.junit.jupiter.api.Assertions;
12+
import org.junit.jupiter.api.Test;
1813

1914
/**
2015
* @author Steve Ebersole
2116
*/
22-
public class CfgXmlParsingTest extends BaseUnitTestCase {
17+
public class CfgXmlParsingTest {
2318
@Test
2419
public void testCfgXmlWithSchemaLocation() {
25-
StandardServiceRegistry ssr = ServiceRegistryUtil.serviceRegistryBuilder()
20+
try (var ssr = ServiceRegistryUtil.serviceRegistryBuilder()
2621
.configure( "org/hibernate/orm/test/boot/cfgXml/hibernate.cfg.xml" )
27-
.build();
28-
try {
22+
.build()) {
2923
final ConfigurationService cs = ssr.getService( ConfigurationService.class );
3024
// augmented form
31-
assertNotNull( cs.getSettings().get( "hibernate.cache.provider_class" ) );
25+
Assertions.assertNotNull( cs.getSettings().get( "hibernate.cache.provider_class" ) );
3226
// original form
33-
assertNotNull( cs.getSettings().get( "cache.provider_class" ) );
34-
}
35-
finally {
36-
StandardServiceRegistryBuilder.destroy( ssr );
27+
Assertions.assertNotNull( cs.getSettings().get( "cache.provider_class" ) );
3728
}
3829
}
3930

40-
@Test(expected = ConfigurationException.class )
31+
@Test
32+
@ExpectedException(ConfigurationException.class)
4133
public void testCfgXmlWithBadNamespaceAndSchemaLocation() {
42-
StandardServiceRegistry ssr = ServiceRegistryUtil.serviceRegistryBuilder()
34+
try (var ssr = ServiceRegistryUtil.serviceRegistryBuilder()
4335
.configure( "org/hibernate/orm/test/boot/cfgXml/badnamespace.cfg.xml" )
44-
.build();
45-
StandardServiceRegistryBuilder.destroy( ssr );
46-
fail( "Expecting the bad namespace to fail" );
36+
.build()) {
37+
Assertions.fail( "Expecting the bad namespace to fail" );
38+
}
4739
}
4840
}

hibernate-core/src/test/java/org/hibernate/orm/test/cdi/general/hibernatesearch/extended/HibernateSearchExtendedCdiSupportTest.java

Lines changed: 74 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,14 @@
77
import jakarta.enterprise.inject.Instance;
88
import jakarta.enterprise.inject.se.SeContainer;
99
import jakarta.enterprise.inject.se.SeContainerInitializer;
10-
1110
import org.hibernate.boot.MetadataSources;
1211
import org.hibernate.boot.registry.BootstrapServiceRegistry;
1312
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
1413
import org.hibernate.boot.registry.StandardServiceRegistry;
1514
import org.hibernate.boot.spi.MetadataImplementor;
1615
import org.hibernate.engine.spi.SessionFactoryImplementor;
17-
import org.hibernate.testing.orm.junit.BaseUnitTest;
18-
import org.hibernate.tool.schema.Action;
19-
20-
import org.hibernate.testing.util.ServiceRegistryUtil;
21-
22-
import org.hibernate.orm.test.cdi.general.hibernatesearch.Monitor;
2316
import org.hibernate.orm.test.cdi.general.hibernatesearch.HibernateSearchSimulatedIntegrator;
17+
import org.hibernate.orm.test.cdi.general.hibernatesearch.Monitor;
2418
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheAlternativeNamedApplicationScopedBeanImpl;
2519
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheAlternativeNamedDependentBeanImpl;
2620
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheApplicationScopedBean;
@@ -35,11 +29,14 @@
3529
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheNonHibernateBeanConsumer;
3630
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheSharedApplicationScopedBean;
3731
import org.hibernate.orm.test.cdi.testsupport.TestingExtendedBeanManager;
38-
import org.junit.Test;
32+
import org.hibernate.testing.orm.junit.BaseUnitTest;
33+
import org.hibernate.testing.util.ServiceRegistryUtil;
34+
import org.hibernate.tool.schema.Action;
35+
import org.junit.jupiter.api.Assertions;
36+
import org.junit.jupiter.api.Test;
3937

4038
import static org.hibernate.cfg.ManagedBeanSettings.JAKARTA_CDI_BEAN_MANAGER;
4139
import static org.hibernate.cfg.SchemaToolingSettings.HBM2DDL_AUTO;
42-
import static org.junit.Assert.assertEquals;
4340

4441
/**
4542
* Tests support for requesting CDI beans in Hibernate Search
@@ -102,17 +99,21 @@ public void test() {
10299

103100
// Here, the HibernateSearchSimulatedIntegrator has just been integrated and has requested beans
104101
// BUT it has not fetched instances of beans yet, so non-shared beans should not have been instantiated yet.
105-
assertEquals( 0, Monitor.theApplicationScopedBean().currentInstantiationCount() );
106-
assertEquals( 0, Monitor.theMainNamedApplicationScopedBean().currentInstantiationCount() );
107-
assertEquals( 0, Monitor.theAlternativeNamedApplicationScopedBean().currentInstantiationCount() );
108-
assertEquals( 1, Monitor.theSharedApplicationScopedBean().currentInstantiationCount() );
109-
assertEquals( 0, Monitor.theDependentBean().currentInstantiationCount() );
110-
assertEquals( 0, Monitor.theMainNamedDependentBean().currentInstantiationCount() );
111-
assertEquals( 0, Monitor.theAlternativeNamedDependentBean().currentInstantiationCount() );
112-
assertEquals( 0, fallbackBeanInstanceProducer.currentInstantiationCount() );
113-
assertEquals( 0, fallbackBeanInstanceProducer.currentNamedInstantiationCount() );
102+
Assertions.assertEquals( 0, Monitor.theApplicationScopedBean().currentInstantiationCount() );
103+
Assertions.assertEquals( 0,
104+
Monitor.theMainNamedApplicationScopedBean().currentInstantiationCount() );
105+
Assertions.assertEquals( 0,
106+
Monitor.theAlternativeNamedApplicationScopedBean().currentInstantiationCount() );
107+
Assertions.assertEquals( 1,
108+
Monitor.theSharedApplicationScopedBean().currentInstantiationCount() );
109+
Assertions.assertEquals( 0, Monitor.theDependentBean().currentInstantiationCount() );
110+
Assertions.assertEquals( 0, Monitor.theMainNamedDependentBean().currentInstantiationCount() );
111+
Assertions.assertEquals( 0,
112+
Monitor.theAlternativeNamedDependentBean().currentInstantiationCount() );
113+
Assertions.assertEquals( 0, fallbackBeanInstanceProducer.currentInstantiationCount() );
114+
Assertions.assertEquals( 0, fallbackBeanInstanceProducer.currentNamedInstantiationCount() );
114115
// Nested dependent bean: 1 instance per bean that depends on it
115-
assertEquals( 1, Monitor.theNestedDependentBean().currentInstantiationCount() );
116+
Assertions.assertEquals( 1, Monitor.theNestedDependentBean().currentInstantiationCount() );
116117

117118
extendedBeanManager.notifyListenerReady( cdiContainer.getBeanManager() );
118119

@@ -123,68 +124,80 @@ public void test() {
123124
// See HibernateSearchSimulatedIntegrator for a detailed list of requested beans
124125

125126
// Application scope: maximum 1 instance as soon as at least one was requested
126-
assertEquals( 1, Monitor.theApplicationScopedBean().currentInstantiationCount() );
127-
assertEquals( 1, Monitor.theMainNamedApplicationScopedBean().currentInstantiationCount() );
128-
assertEquals( 0, Monitor.theAlternativeNamedApplicationScopedBean().currentInstantiationCount() );
129-
assertEquals( 1, Monitor.theSharedApplicationScopedBean().currentInstantiationCount() );
127+
Assertions.assertEquals( 1, Monitor.theApplicationScopedBean().currentInstantiationCount() );
128+
Assertions.assertEquals( 1,
129+
Monitor.theMainNamedApplicationScopedBean().currentInstantiationCount() );
130+
Assertions.assertEquals( 0,
131+
Monitor.theAlternativeNamedApplicationScopedBean().currentInstantiationCount() );
132+
Assertions.assertEquals( 1,
133+
Monitor.theSharedApplicationScopedBean().currentInstantiationCount() );
130134

131135
// Dependent scope: 1 instance per bean we requested explicitly
132-
assertEquals( 2, Monitor.theDependentBean().currentInstantiationCount() );
133-
assertEquals( 2, Monitor.theMainNamedDependentBean().currentInstantiationCount() );
134-
assertEquals( 0, Monitor.theAlternativeNamedDependentBean().currentInstantiationCount() );
136+
Assertions.assertEquals( 2, Monitor.theDependentBean().currentInstantiationCount() );
137+
Assertions.assertEquals( 2, Monitor.theMainNamedDependentBean().currentInstantiationCount() );
138+
Assertions.assertEquals( 0,
139+
Monitor.theAlternativeNamedDependentBean().currentInstantiationCount() );
135140

136141
// Reflection-instantiated: 1 instance per bean we requested explicitly
137-
assertEquals( 2, fallbackBeanInstanceProducer.currentInstantiationCount() );
138-
assertEquals( 2, fallbackBeanInstanceProducer.currentNamedInstantiationCount() );
142+
Assertions.assertEquals( 2, fallbackBeanInstanceProducer.currentInstantiationCount() );
143+
Assertions.assertEquals( 2, fallbackBeanInstanceProducer.currentNamedInstantiationCount() );
139144

140145
// Nested dependent bean: 1 instance per bean that depends on it
141-
assertEquals( 7, Monitor.theNestedDependentBean().currentInstantiationCount() );
146+
Assertions.assertEquals( 7, Monitor.theNestedDependentBean().currentInstantiationCount() );
142147

143148
// Expect one PostConstruct call per CDI bean instance
144-
assertEquals( 1, Monitor.theApplicationScopedBean().currentPostConstructCount() );
145-
assertEquals( 1, Monitor.theMainNamedApplicationScopedBean().currentPostConstructCount() );
146-
assertEquals( 0, Monitor.theAlternativeNamedApplicationScopedBean().currentPostConstructCount() );
147-
assertEquals( 1, Monitor.theSharedApplicationScopedBean().currentPostConstructCount() );
148-
assertEquals( 2, Monitor.theDependentBean().currentPostConstructCount() );
149-
assertEquals( 2, Monitor.theMainNamedDependentBean().currentPostConstructCount() );
150-
assertEquals( 0, Monitor.theAlternativeNamedDependentBean().currentPostConstructCount() );
151-
assertEquals( 7, Monitor.theNestedDependentBean().currentPostConstructCount() );
149+
Assertions.assertEquals( 1, Monitor.theApplicationScopedBean().currentPostConstructCount() );
150+
Assertions.assertEquals( 1,
151+
Monitor.theMainNamedApplicationScopedBean().currentPostConstructCount() );
152+
Assertions.assertEquals( 0,
153+
Monitor.theAlternativeNamedApplicationScopedBean().currentPostConstructCount() );
154+
Assertions.assertEquals( 1,
155+
Monitor.theSharedApplicationScopedBean().currentPostConstructCount() );
156+
Assertions.assertEquals( 2, Monitor.theDependentBean().currentPostConstructCount() );
157+
Assertions.assertEquals( 2, Monitor.theMainNamedDependentBean().currentPostConstructCount() );
158+
Assertions.assertEquals( 0,
159+
Monitor.theAlternativeNamedDependentBean().currentPostConstructCount() );
160+
Assertions.assertEquals( 7, Monitor.theNestedDependentBean().currentPostConstructCount() );
152161

153162
// Expect no PreDestroy call yet
154-
assertEquals( 0, Monitor.theApplicationScopedBean().currentPreDestroyCount() );
155-
assertEquals( 0, Monitor.theMainNamedApplicationScopedBean().currentPreDestroyCount() );
156-
assertEquals( 0, Monitor.theAlternativeNamedApplicationScopedBean().currentPreDestroyCount() );
157-
assertEquals( 0, Monitor.theSharedApplicationScopedBean().currentPreDestroyCount() );
158-
assertEquals( 0, Monitor.theDependentBean().currentPreDestroyCount() );
159-
assertEquals( 0, Monitor.theMainNamedDependentBean().currentPreDestroyCount() );
160-
assertEquals( 0, Monitor.theAlternativeNamedDependentBean().currentPreDestroyCount() );
161-
assertEquals( 0, Monitor.theNestedDependentBean().currentPreDestroyCount() );
163+
Assertions.assertEquals( 0, Monitor.theApplicationScopedBean().currentPreDestroyCount() );
164+
Assertions.assertEquals( 0,
165+
Monitor.theMainNamedApplicationScopedBean().currentPreDestroyCount() );
166+
Assertions.assertEquals( 0,
167+
Monitor.theAlternativeNamedApplicationScopedBean().currentPreDestroyCount() );
168+
Assertions.assertEquals( 0, Monitor.theSharedApplicationScopedBean().currentPreDestroyCount() );
169+
Assertions.assertEquals( 0, Monitor.theDependentBean().currentPreDestroyCount() );
170+
Assertions.assertEquals( 0, Monitor.theMainNamedDependentBean().currentPreDestroyCount() );
171+
Assertions.assertEquals( 0,
172+
Monitor.theAlternativeNamedDependentBean().currentPreDestroyCount() );
173+
Assertions.assertEquals( 0, Monitor.theNestedDependentBean().currentPreDestroyCount() );
162174
}
163175

164176
// After the CDI context has ended, PreDestroy should have been called on every "normal-scoped" CDI bean
165177
// (i.e. all CDI beans excepting the dependent ones we requested explicitly and haven't released yet)
166-
assertEquals( 1, Monitor.theApplicationScopedBean().currentPreDestroyCount() );
167-
assertEquals( 1, Monitor.theMainNamedApplicationScopedBean().currentPreDestroyCount() );
168-
assertEquals( 0, Monitor.theAlternativeNamedApplicationScopedBean().currentPreDestroyCount() );
169-
assertEquals( 1, Monitor.theSharedApplicationScopedBean().currentPreDestroyCount() );
170-
assertEquals( 0, Monitor.theDependentBean().currentPreDestroyCount() );
171-
assertEquals( 0, Monitor.theMainNamedDependentBean().currentPreDestroyCount() );
172-
assertEquals( 0, Monitor.theAlternativeNamedDependentBean().currentPreDestroyCount() );
173-
assertEquals( 3, Monitor.theNestedDependentBean().currentPreDestroyCount() );
178+
Assertions.assertEquals( 1, Monitor.theApplicationScopedBean().currentPreDestroyCount() );
179+
Assertions.assertEquals( 1, Monitor.theMainNamedApplicationScopedBean().currentPreDestroyCount() );
180+
Assertions.assertEquals( 0,
181+
Monitor.theAlternativeNamedApplicationScopedBean().currentPreDestroyCount() );
182+
Assertions.assertEquals( 1, Monitor.theSharedApplicationScopedBean().currentPreDestroyCount() );
183+
Assertions.assertEquals( 0, Monitor.theDependentBean().currentPreDestroyCount() );
184+
Assertions.assertEquals( 0, Monitor.theMainNamedDependentBean().currentPreDestroyCount() );
185+
Assertions.assertEquals( 0, Monitor.theAlternativeNamedDependentBean().currentPreDestroyCount() );
186+
Assertions.assertEquals( 3, Monitor.theNestedDependentBean().currentPreDestroyCount() );
174187
}
175188
}
176189
}
177190

178191
// Here, the HibernateSearchSimulatedIntegrator has just been disintegrated and has released beans
179192
// The dependent beans should now have been released as well.
180-
assertEquals( 1, Monitor.theApplicationScopedBean().currentPreDestroyCount() );
181-
assertEquals( 1, Monitor.theMainNamedApplicationScopedBean().currentPreDestroyCount() );
182-
assertEquals( 0, Monitor.theAlternativeNamedApplicationScopedBean().currentPreDestroyCount() );
183-
assertEquals( 1, Monitor.theSharedApplicationScopedBean().currentPreDestroyCount() );
184-
assertEquals( 2, Monitor.theDependentBean().currentPreDestroyCount() );
185-
assertEquals( 2, Monitor.theMainNamedDependentBean().currentPreDestroyCount() );
186-
assertEquals( 0, Monitor.theAlternativeNamedDependentBean().currentPreDestroyCount() );
187-
assertEquals( 7, Monitor.theNestedDependentBean().currentPreDestroyCount() );
193+
Assertions.assertEquals( 1, Monitor.theApplicationScopedBean().currentPreDestroyCount() );
194+
Assertions.assertEquals( 1, Monitor.theMainNamedApplicationScopedBean().currentPreDestroyCount() );
195+
Assertions.assertEquals( 0, Monitor.theAlternativeNamedApplicationScopedBean().currentPreDestroyCount() );
196+
Assertions.assertEquals( 1, Monitor.theSharedApplicationScopedBean().currentPreDestroyCount() );
197+
Assertions.assertEquals( 2, Monitor.theDependentBean().currentPreDestroyCount() );
198+
Assertions.assertEquals( 2, Monitor.theMainNamedDependentBean().currentPreDestroyCount() );
199+
Assertions.assertEquals( 0, Monitor.theAlternativeNamedDependentBean().currentPreDestroyCount() );
200+
Assertions.assertEquals( 7, Monitor.theNestedDependentBean().currentPreDestroyCount() );
188201
}
189202

190203
}

hibernate-core/src/test/java/org/hibernate/orm/test/embeddable/OrderByEmbeddableToOneTest.java

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,48 @@
44
*/
55
package org.hibernate.orm.test.embeddable;
66

7-
import java.util.ArrayList;
8-
import java.util.List;
97
import jakarta.persistence.Basic;
108
import jakarta.persistence.ElementCollection;
119
import jakarta.persistence.Embeddable;
1210
import jakarta.persistence.Entity;
1311
import jakarta.persistence.Id;
1412
import jakarta.persistence.ManyToOne;
1513
import jakarta.persistence.OrderBy;
16-
1714
import org.hibernate.Session;
18-
import org.hibernate.cfg.Configuration;
19-
import org.hibernate.metamodel.CollectionClassification;
2015
import org.hibernate.query.Query;
16+
import org.hibernate.testing.orm.junit.DomainModel;
17+
import org.hibernate.testing.orm.junit.SessionFactory;
18+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
19+
import org.junit.jupiter.api.AfterEach;
20+
import org.junit.jupiter.api.Test;
2121

22-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
23-
import org.junit.Test;
22+
import java.util.ArrayList;
23+
import java.util.List;
2424

2525
import static org.assertj.core.api.Assertions.assertThat;
26-
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
27-
28-
public class OrderByEmbeddableToOneTest extends BaseCoreFunctionalTestCase {
29-
30-
@Override
31-
protected Class<?>[] getAnnotatedClasses() {
32-
return new Class[] { Containing.class, Embed.class, Contained.class };
33-
}
3426

35-
@Override
36-
protected void configure(Configuration configuration) {
37-
super.configure( configuration );
38-
configuration.setProperty( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG );
27+
@SuppressWarnings("JUnitMalformedDeclaration")
28+
@DomainModel(annotatedClasses = {
29+
OrderByEmbeddableToOneTest.Containing.class,
30+
OrderByEmbeddableToOneTest.Embed.class,
31+
OrderByEmbeddableToOneTest.Contained.class
32+
})
33+
@SessionFactory
34+
public class OrderByEmbeddableToOneTest {
35+
@AfterEach
36+
void tearDown(SessionFactoryScope factoryScope) {
37+
factoryScope.dropData();
3938
}
4039

4140
@Test
42-
public void test() {
43-
inTransaction( session -> {
41+
public void test(SessionFactoryScope factoryScope) {
42+
factoryScope.inTransaction( session -> {
4443
saveComposition( session, 1 );
4544
saveComposition( session, 11 );
4645
saveComposition( session, 21 );
4746
} );
4847

49-
inTransaction( session -> {
48+
factoryScope.inTransaction( session -> {
5049
Query<Containing> query = session.createQuery( "select c from containing c order by c.id asc", Containing.class );
5150

5251
List<Containing> resultList = query.getResultList();

0 commit comments

Comments
 (0)