Skip to content

Commit 48473d9

Browse files
committed
HHH-19846 Drop JUnit 4 usage
1 parent 92428e5 commit 48473d9

File tree

3 files changed

+98
-72
lines changed

3 files changed

+98
-72
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/idmanytoone/IdManyToOneTest.java

Lines changed: 61 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,71 @@
99
import jakarta.persistence.criteria.Join;
1010
import jakarta.persistence.criteria.JoinType;
1111
import jakarta.persistence.criteria.Root;
12-
13-
import org.hibernate.Session;
12+
import org.hibernate.boot.model.naming.ImplicitNamingStrategy;
1413
import org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl;
15-
import org.hibernate.cfg.Configuration;
16-
14+
import org.hibernate.cfg.AvailableSettings;
15+
import org.hibernate.testing.orm.junit.DomainModel;
1716
import org.hibernate.testing.orm.junit.JiraKey;
18-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
19-
import org.junit.Test;
17+
import org.hibernate.testing.orm.junit.ServiceRegistry;
18+
import org.hibernate.testing.orm.junit.SessionFactory;
19+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
20+
import org.hibernate.testing.orm.junit.SettingProvider;
21+
import org.junit.jupiter.api.Test;
2022

21-
import static org.junit.Assert.assertEquals;
23+
import static org.assertj.core.api.Assertions.assertThat;
2224

2325
/**
2426
* @author Emmanuel Bernard
2527
*/
26-
public class IdManyToOneTest extends BaseCoreFunctionalTestCase {
28+
@DomainModel(
29+
annotatedClasses = {
30+
Store.class,
31+
Customer.class,
32+
StoreCustomer.class,
33+
CardKey.class,
34+
CardField.class,
35+
Card.class,
36+
Project.class,
37+
Course.class,
38+
Student.class,
39+
CourseStudent.class,
40+
41+
//tested only through deployment
42+
//ANN-590 testIdClassManyToOneWithReferenceColumn
43+
Customers.class,
44+
ShoppingBaskets.class,
45+
ShoppingBasketsPK.class,
46+
BasketItems.class,
47+
BasketItemsPK.class
48+
}
49+
)
50+
@ServiceRegistry(
51+
settingProviders = @SettingProvider(settingName = AvailableSettings.IMPLICIT_NAMING_STRATEGY,
52+
provider = IdManyToOneTest.ImplicitNameSettingProvider.class)
53+
)
54+
@SessionFactory
55+
public class IdManyToOneTest {
56+
57+
public static class ImplicitNameSettingProvider implements SettingProvider.Provider<ImplicitNamingStrategy> {
58+
59+
@Override
60+
public ImplicitNamingStrategy getSetting() {
61+
return ImplicitNamingStrategyJpaCompliantImpl.INSTANCE;
62+
}
63+
}
64+
2765
@Test
28-
public void testFkCreationOrdering() {
66+
public void testFkCreationOrdering(SessionFactoryScope scope) {
2967
//no real test case, the sessionFactory building is tested
30-
Session s = openSession();
31-
s.close();
68+
scope.inTransaction(
69+
session -> {
70+
}
71+
);
3272
}
3373

3474
@Test
35-
public void testIdClassManyToOne() {
36-
inTransaction( s-> {
75+
public void testIdClassManyToOne(SessionFactoryScope scope) {
76+
scope.inTransaction( s -> {
3777
Store store = new Store();
3878
Customer customer = new Customer();
3979
s.persist( store );
@@ -43,18 +83,19 @@ public void testIdClassManyToOne() {
4383
s.flush();
4484
s.clear();
4585

46-
store = s.get(Store.class, store.id );
47-
assertEquals( 1, store.customers.size() );
48-
assertEquals( customer.id, store.customers.iterator().next().customer.id );
86+
store = s.find( Store.class, store.id );
87+
assertThat( store.customers.size() ).isEqualTo( 1 );
88+
assertThat( store.customers.iterator().next().customer.id ).isEqualTo( customer.id );
4989
} );
5090
//TODO test Customers / ShoppingBaskets / BasketItems testIdClassManyToOneWithReferenceColumn
5191
}
5292

5393
@Test
54-
@JiraKey( value = "HHH-7767" )
55-
public void testCriteriaRestrictionOnIdManyToOne() {
56-
inTransaction( s -> {
57-
s.createQuery( "from Course c join c.students cs join cs.student s where s.name = 'Foo'", Object[].class ).list();
94+
@JiraKey(value = "HHH-7767")
95+
public void testCriteriaRestrictionOnIdManyToOne(SessionFactoryScope scope) {
96+
scope.inTransaction( s -> {
97+
s.createQuery( "from Course c join c.students cs join cs.student s where s.name = 'Foo'", Object[].class )
98+
.list();
5899

59100
CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder();
60101
CriteriaQuery<Course> criteria = criteriaBuilder.createQuery( Course.class );
@@ -77,34 +118,4 @@ public void testCriteriaRestrictionOnIdManyToOne() {
77118
// criteria2.list();
78119
} );
79120
}
80-
81-
@Override
82-
protected Class[] getAnnotatedClasses() {
83-
return new Class[] {
84-
Store.class,
85-
Customer.class,
86-
StoreCustomer.class,
87-
CardKey.class,
88-
CardField.class,
89-
Card.class,
90-
Project.class,
91-
Course.class,
92-
Student.class,
93-
CourseStudent.class,
94-
95-
//tested only through deployment
96-
//ANN-590 testIdClassManyToOneWithReferenceColumn
97-
Customers.class,
98-
ShoppingBaskets.class,
99-
ShoppingBasketsPK.class,
100-
BasketItems.class,
101-
BasketItemsPK.class
102-
};
103-
}
104-
105-
@Override
106-
protected void configure(Configuration configuration) {
107-
super.configure( configuration );
108-
configuration.setImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE );
109-
}
110121
}

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/idmanytoone/alphabetical/AlphabeticalIdManyToOneTest.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,30 @@
44
*/
55
package org.hibernate.orm.test.annotations.idmanytoone.alphabetical;
66

7-
import org.junit.Test;
8-
9-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
7+
import org.hibernate.testing.orm.junit.DomainModel;
8+
import org.hibernate.testing.orm.junit.SessionFactory;
9+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
10+
import org.junit.jupiter.api.Test;
1011

1112
/**
1213
* @author Emmanuel Bernard
1314
*/
14-
public class AlphabeticalIdManyToOneTest extends BaseCoreFunctionalTestCase {
15+
@DomainModel(
16+
annotatedClasses = {
17+
B.class,
18+
C.class,
19+
A.class
20+
}
21+
)
22+
@SessionFactory
23+
public class AlphabeticalIdManyToOneTest {
24+
1525
@Test
16-
public void testAlphabeticalTest() throws Exception {
26+
public void testAlphabeticalTest(SessionFactoryScope scope) {
1727
//test through deployment
18-
}
19-
20-
@Override
21-
protected Class[] getAnnotatedClasses() {
22-
return new Class[] { B.class, C.class, A.class };
28+
scope.inTransaction(
29+
session -> {
30+
}
31+
);
2332
}
2433
}

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/idmanytoone/alphabetical/AlphabeticalManyToOneTest.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,32 @@
44
*/
55
package org.hibernate.orm.test.annotations.idmanytoone.alphabetical;
66

7-
import org.junit.Test;
87

9-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
8+
import org.hibernate.testing.orm.junit.DomainModel;
9+
import org.hibernate.testing.orm.junit.SessionFactory;
10+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
11+
import org.junit.jupiter.api.Test;
1012

1113
/**
1214
* @author Emmanuel Bernard
1315
*/
14-
public class AlphabeticalManyToOneTest extends BaseCoreFunctionalTestCase {
15-
@Test
16-
public void testAlphabeticalTest() throws Exception {
17-
//test through deployment
18-
}
19-
20-
@Override
21-
protected Class[] getAnnotatedClasses() {
22-
return new Class[] {
16+
@DomainModel(
17+
annotatedClasses = {
2318
Acces.class,
2419
Droitacces.class,
2520
Benefserv.class,
2621
Service.class
27-
};
22+
}
23+
)
24+
@SessionFactory
25+
public class AlphabeticalManyToOneTest {
26+
27+
@Test
28+
public void testAlphabeticalTest(SessionFactoryScope scope) {
29+
//test through deployment
30+
scope.inTransaction(
31+
session -> {
32+
}
33+
);
2834
}
2935
}

0 commit comments

Comments
 (0)