Skip to content

Commit 4f9f02b

Browse files
committed
HHH-19846 Drop JUnit 4 usage
1 parent 7acfe10 commit 4f9f02b

File tree

4 files changed

+125
-136
lines changed

4 files changed

+125
-136
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/fetchprofile/Customer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class Customer {
3838
private long customerNumber;
3939

4040
@OneToMany
41-
private Set<Order> orders = new HashSet<Order>();
41+
private Set<Order> orders = new HashSet<>();
4242

4343
@ManyToOne(fetch = FetchType.LAZY)
4444
private Order lastOrder;

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/fetchprofile/MappedByFetchProfileFunctionTest.java

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,48 @@
55
package org.hibernate.orm.test.annotations.fetchprofile;
66

77
import org.hibernate.Hibernate;
8-
import org.hibernate.Session;
9-
import org.hibernate.Transaction;
108
import org.hibernate.orm.test.annotations.fetchprofile.mappedby.Address;
11-
9+
import org.hibernate.testing.orm.junit.DomainModel;
1210
import org.hibernate.testing.orm.junit.JiraKey;
13-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
14-
import org.junit.Test;
15-
16-
import static org.junit.Assert.assertTrue;
11+
import org.hibernate.testing.orm.junit.SessionFactory;
12+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
13+
import org.junit.jupiter.api.Test;
1714

18-
@JiraKey( value = "HHH-14071" )
19-
public class MappedByFetchProfileFunctionTest extends BaseCoreFunctionalTestCase {
15+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
2016

21-
@Test
22-
public void testFetchWithOneToOneMappedBy() {
23-
final Session session = openSession();
24-
session.enableFetchProfile( "address-with-customer" );
25-
final Transaction transaction = session.beginTransaction();
26-
27-
Address address = new Address();
28-
address.setStreet("Test Road 1");
29-
Customer6 customer = new Customer6();
30-
customer.setName("Tester");
31-
customer.setAddress(address);
32-
33-
session.persist(address);
34-
session.persist(customer);
35-
36-
session.flush();
37-
session.clear();
38-
39-
address = session.get(Address.class, address.getId());
40-
assertTrue(Hibernate.isInitialized(address.getCustomer()));
41-
session.remove(address.getCustomer());
42-
session.remove(address);
43-
44-
transaction.commit();
45-
session.close();
46-
}
47-
48-
@Override
49-
protected Class<?>[] getAnnotatedClasses() {
50-
return new Class<?>[] {
17+
@JiraKey(value = "HHH-14071")
18+
@DomainModel(
19+
annotatedClasses = {
5120
Customer6.class,
5221
Address.class
53-
};
22+
}
23+
)
24+
@SessionFactory
25+
public class MappedByFetchProfileFunctionTest {
26+
27+
@Test
28+
public void testFetchWithOneToOneMappedBy(SessionFactoryScope scope) {
29+
scope.inTransaction(
30+
session -> {
31+
session.enableFetchProfile( "address-with-customer" );
32+
Address address = new Address();
33+
address.setStreet( "Test Road 1" );
34+
Customer6 customer = new Customer6();
35+
customer.setName( "Tester" );
36+
customer.setAddress( address );
37+
38+
session.persist( address );
39+
session.persist( customer );
40+
41+
session.flush();
42+
session.clear();
43+
44+
address = session.get( Address.class, address.getId() );
45+
assertThat( Hibernate.isInitialized( address.getCustomer() ) ).isTrue();
46+
session.remove( address.getCustomer() );
47+
session.remove( address );
48+
}
49+
);
5450
}
5551

5652
}

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/fetchprofile/MappedByFetchProfileUnitTest.java

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,47 @@
99
import org.hibernate.engine.spi.SessionFactoryImplementor;
1010
import org.hibernate.orm.test.annotations.fetchprofile.mappedby.Address;
1111
import org.hibernate.service.ServiceRegistry;
12-
1312
import org.hibernate.testing.ServiceRegistryBuilder;
13+
import org.hibernate.testing.orm.junit.BaseUnitTest;
1414
import org.hibernate.testing.orm.junit.JiraKey;
15-
import org.hibernate.testing.junit4.BaseUnitTestCase;
16-
import org.junit.After;
17-
import org.junit.Before;
18-
import org.junit.Test;
15+
import org.junit.jupiter.api.AfterEach;
16+
import org.junit.jupiter.api.BeforeEach;
17+
import org.junit.jupiter.api.Test;
1918

20-
import static org.junit.Assert.assertTrue;
19+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
2120

22-
@JiraKey( value = "HHH-14071" )
23-
public class MappedByFetchProfileUnitTest extends BaseUnitTestCase {
21+
@JiraKey(value = "HHH-14071")
22+
@BaseUnitTest
23+
public class MappedByFetchProfileUnitTest {
2424

2525
private ServiceRegistry serviceRegistry;
2626

27-
@Before
27+
@BeforeEach
2828
public void setUp() {
2929
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
3030
}
3131

32-
@After
32+
@AfterEach
3333
public void tearDown() {
34-
if (serviceRegistry != null) ServiceRegistryBuilder.destroy(serviceRegistry);
34+
if ( serviceRegistry != null ) {
35+
ServiceRegistryBuilder.destroy( serviceRegistry );
36+
}
3537
}
3638

3739
@Test
3840
public void testFetchProfileConfigured() {
3941
Configuration config = new Configuration();
4042
config.addAnnotatedClass( Customer6.class );
4143
config.addAnnotatedClass( Address.class );
42-
try (SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
43-
serviceRegistry
44-
)) {
44+
try (SessionFactoryImplementor sessionImpl = (SessionFactoryImplementor) config
45+
.buildSessionFactory( serviceRegistry )) {
4546

46-
assertTrue(
47-
"fetch profile not parsed properly",
48-
sessionImpl.containsFetchProfileDefinition( "address-with-customer" )
49-
);
50-
assertTrue(
51-
"fetch profile not parsed properly",
52-
sessionImpl.containsFetchProfileDefinition( "customer-with-address" )
53-
);
47+
assertThat( sessionImpl.containsFetchProfileDefinition( "address-with-customer" ) )
48+
.describedAs( "fetch profile not parsed properly" )
49+
.isTrue();
50+
assertThat( sessionImpl.containsFetchProfileDefinition( "customer-with-address" ) )
51+
.describedAs( "fetch profile not parsed properly" )
52+
.isTrue();
5453
}
5554
}
5655

@@ -60,18 +59,15 @@ public void testPackageConfiguredFetchProfile() {
6059
config.addAnnotatedClass( Customer6.class );
6160
config.addAnnotatedClass( Address.class );
6261
config.addPackage( Address.class.getPackage().getName() );
63-
try (SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory(
64-
serviceRegistry
65-
)) {
62+
try (SessionFactoryImplementor sessionImpl = (SessionFactoryImplementor) config
63+
.buildSessionFactory( serviceRegistry )) {
6664

67-
assertTrue(
68-
"fetch profile not parsed properly",
69-
sessionImpl.containsFetchProfileDefinition( "mappedBy-package-profile-1" )
70-
);
71-
assertTrue(
72-
"fetch profile not parsed properly",
73-
sessionImpl.containsFetchProfileDefinition( "mappedBy-package-profile-2" )
74-
);
65+
assertThat( sessionImpl.containsFetchProfileDefinition( "mappedBy-package-profile-1" ) )
66+
.describedAs( "fetch profile not parsed properly" )
67+
.isTrue();
68+
assertThat( sessionImpl.containsFetchProfileDefinition( "mappedBy-package-profile-2" ) )
69+
.describedAs( "fetch profile not parsed properly" )
70+
.isTrue();
7571
}
7672
}
7773

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/fetchprofile/MoreFetchProfileTest.java

Lines changed: 59 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,79 +4,76 @@
44
*/
55
package org.hibernate.orm.test.annotations.fetchprofile;
66

7-
import java.util.Date;
8-
9-
import org.junit.Test;
10-
117
import org.hibernate.Hibernate;
12-
import org.hibernate.Session;
13-
import org.hibernate.Transaction;
14-
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;
12+
13+
import java.util.Date;
1514

16-
import static org.junit.Assert.assertTrue;
15+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
1716

1817
/**
1918
* @author Emmanuel Bernard
2019
* @author Hardy Ferentschik
2120
*/
22-
public class MoreFetchProfileTest extends BaseCoreFunctionalTestCase {
23-
@Test
24-
public void testFetchWithTwoOverrides() throws Exception {
25-
Session s = openSession();
26-
s.enableFetchProfile( "customer-with-orders-and-country" );
27-
final Transaction transaction = s.beginTransaction();
28-
Country ctry = new Country();
29-
ctry.setName( "France" );
30-
Order o = new Order();
31-
o.setCountry( ctry );
32-
o.setDeliveryDate( new Date() );
33-
o.setOrderNumber( 1 );
34-
Order o2 = new Order();
35-
o2.setCountry( ctry );
36-
o2.setDeliveryDate( new Date() );
37-
o2.setOrderNumber( 2 );
38-
Customer c = new Customer();
39-
c.setCustomerNumber( 1 );
40-
c.setName( "Emmanuel" );
41-
c.getOrders().add( o );
42-
c.setLastOrder( o2 );
43-
44-
s.persist( ctry );
45-
s.persist( o );
46-
s.persist( o2 );
47-
s.persist( c );
48-
49-
s.flush();
21+
@DomainModel(
22+
annotatedClasses = {
23+
Order.class,
24+
Country.class,
25+
Customer.class,
26+
SupportTickets.class
27+
}
28+
)
29+
@SessionFactory
30+
public class MoreFetchProfileTest {
5031

51-
s.clear();
32+
@Test
33+
public void testFetchWithTwoOverrides(SessionFactoryScope scope) {
34+
scope.inTransaction(
35+
session -> {
36+
session.enableFetchProfile( "customer-with-orders-and-country" );
37+
Country ctry = new Country();
38+
ctry.setName( "France" );
39+
Order o = new Order();
40+
o.setCountry( ctry );
41+
o.setDeliveryDate( new Date() );
42+
o.setOrderNumber( 1 );
43+
Order o2 = new Order();
44+
o2.setCountry( ctry );
45+
o2.setDeliveryDate( new Date() );
46+
o2.setOrderNumber( 2 );
47+
Customer c = new Customer();
48+
c.setCustomerNumber( 1 );
49+
c.setName( "Emmanuel" );
50+
c.getOrders().add( o );
51+
c.setLastOrder( o2 );
5252

53-
c = ( Customer ) s.get( Customer.class, c.getId() );
54-
assertTrue( Hibernate.isInitialized( c.getLastOrder() ) );
55-
assertTrue( Hibernate.isInitialized( c.getOrders() ) );
56-
for ( Order so : c.getOrders() ) {
57-
assertTrue( Hibernate.isInitialized( so.getCountry() ) );
58-
}
59-
final Order order = c.getOrders().iterator().next();
60-
c.getOrders().remove( order );
61-
s.remove( c );
62-
final Order lastOrder = c.getLastOrder();
63-
c.setLastOrder( null );
64-
s.remove( order.getCountry() );
65-
s.remove( lastOrder );
66-
s.remove( order );
53+
session.persist( ctry );
54+
session.persist( o );
55+
session.persist( o2 );
56+
session.persist( c );
6757

68-
transaction.commit();
69-
s.close();
58+
session.flush();
7059

71-
}
60+
session.clear();
7261

73-
@Override
74-
protected Class<?>[] getAnnotatedClasses() {
75-
return new Class<?>[] {
76-
Order.class,
77-
Country.class,
78-
Customer.class,
79-
SupportTickets.class
80-
};
62+
c = session.find( Customer.class, c.getId() );
63+
assertThat( Hibernate.isInitialized( c.getLastOrder() ) ).isTrue();
64+
assertThat( Hibernate.isInitialized( c.getOrders() ) ).isTrue();
65+
for ( Order so : c.getOrders() ) {
66+
assertThat( Hibernate.isInitialized( so.getCountry() ) ).isTrue();
67+
}
68+
final Order order = c.getOrders().iterator().next();
69+
c.getOrders().remove( order );
70+
session.remove( c );
71+
final Order lastOrder = c.getLastOrder();
72+
c.setLastOrder( null );
73+
session.remove( order.getCountry() );
74+
session.remove( lastOrder );
75+
session.remove( order );
76+
}
77+
);
8178
}
8279
}

0 commit comments

Comments
 (0)