Skip to content

Commit d6434fa

Browse files
committed
HHH-19846 - Remove JUnit4: org.hibernate.orm.test.jpa.callbacks/cascade
Signed-off-by: Jan Schatteman <[email protected]>
1 parent 0d1c7e1 commit d6434fa

File tree

5 files changed

+79
-88
lines changed

5 files changed

+79
-88
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/jpa/callbacks/CallbackAndDirtyTest.java

Lines changed: 73 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -4,99 +4,94 @@
44
*/
55
package org.hibernate.orm.test.jpa.callbacks;
66

7-
import java.util.Iterator;
87
import java.util.List;
9-
import jakarta.persistence.EntityManager;
108

11-
import org.junit.Test;
9+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
10+
import org.hibernate.testing.orm.junit.Jpa;
11+
import org.junit.jupiter.api.Test;
1212

13-
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
14-
15-
import static org.junit.Assert.assertEquals;
16-
import static org.junit.Assert.assertTrue;
13+
import static org.junit.jupiter.api.Assertions.assertEquals;
14+
import static org.junit.jupiter.api.Assertions.assertTrue;
1715

1816
/**
1917
* @author Emmanuel Bernard
2018
*/
21-
public class CallbackAndDirtyTest extends BaseEntityManagerFunctionalTestCase {
19+
@Jpa(annotatedClasses = {
20+
Customer.class,
21+
Employee.class,
22+
Person.class
23+
})
24+
public class CallbackAndDirtyTest {
2225
@Test
23-
public void testDirtyButNotDirty() throws Exception {
24-
EntityManager manager = getOrCreateEntityManager();
25-
manager.getTransaction().begin();
26-
Employee mark = new Employee();
27-
mark.setName( "Mark" );
28-
mark.setTitle( "internal sales" );
29-
mark.setSex( 'M' );
30-
mark.setAddress( "buckhead" );
31-
mark.setZip( "30305" );
32-
mark.setCountry( "USA" );
33-
34-
Customer joe = new Customer();
35-
joe.setName( "Joe" );
36-
joe.setSex( 'M' );
37-
joe.setAddress( "San Francisco" );
38-
joe.setZip( "XXXXX" );
39-
joe.setCountry( "USA" );
40-
joe.setComments( "Very demanding" );
41-
joe.setSalesperson( mark );
26+
public void testDirtyButNotDirty(EntityManagerFactoryScope scope) {
27+
scope.inEntityManager( entityManager -> {
28+
entityManager.getTransaction().begin();
29+
Employee mark = new Employee();
30+
mark.setName( "Mark" );
31+
mark.setTitle( "internal sales" );
32+
mark.setSex( 'M' );
33+
mark.setAddress( "buckhead" );
34+
mark.setZip( "30305" );
35+
mark.setCountry( "USA" );
4236

43-
Person yomomma = new Person();
44-
yomomma.setName( "mum" );
45-
yomomma.setSex( 'F' );
37+
Customer joe = new Customer();
38+
joe.setName( "Joe" );
39+
joe.setSex( 'M' );
40+
joe.setAddress( "San Francisco" );
41+
joe.setZip( "XXXXX" );
42+
joe.setCountry( "USA" );
43+
joe.setComments( "Very demanding" );
44+
joe.setSalesperson( mark );
4645

47-
manager.persist( mark );
48-
manager.persist( joe );
49-
manager.persist( yomomma );
50-
long[] ids = {mark.getId(), joe.getId(), yomomma.getId()};
51-
manager.getTransaction().commit();
46+
Person yomomma = new Person();
47+
yomomma.setName( "mum" );
48+
yomomma.setSex( 'F' );
5249

53-
manager.getTransaction().begin();
54-
assertEquals(
55-
manager.createQuery( "select p.address, p.name from Person p order by p.name" ).getResultList().size(),
56-
3
57-
);
58-
assertEquals( manager.createQuery( "select p from Person p where p.class = Customer" ).getResultList().size(), 1 );
59-
manager.getTransaction().commit();
50+
entityManager.persist( mark );
51+
entityManager.persist( joe );
52+
entityManager.persist( yomomma );
53+
long[] ids = {mark.getId(), joe.getId(), yomomma.getId()};
54+
entityManager.getTransaction().commit();
55+
entityManager.getTransaction().begin();
56+
assertEquals(
57+
3,
58+
entityManager.createQuery( "select p.address, p.name from Person p order by p.name" ).getResultList().size()
59+
);
60+
assertEquals( 1,
61+
entityManager.createQuery( "select p from Person p where p.class = Customer" ).getResultList().size() );
62+
entityManager.getTransaction().commit();
6063

61-
manager.getTransaction().begin();
62-
List customers = manager.createQuery( "select c from Customer c left join fetch c.salesperson" ).getResultList();
63-
for ( Iterator iter = customers.iterator(); iter.hasNext() ; ) {
64-
Customer c = (Customer) iter.next();
65-
assertEquals( c.getSalesperson().getName(), "Mark" );
66-
}
67-
assertEquals( customers.size(), 1 );
68-
manager.getTransaction().commit();
64+
entityManager.getTransaction().begin();
65+
List customers = entityManager.createQuery( "select c from Customer c left join fetch c.salesperson" ).getResultList();
66+
for ( Object customer : customers ) {
67+
Customer c = (Customer) customer;
68+
assertEquals( "Mark", c.getSalesperson().getName() );
69+
}
70+
assertEquals( 1, customers.size() );
71+
entityManager.getTransaction().commit();
6972

70-
manager.getTransaction().begin();
71-
customers = manager.createQuery( "select c from Customer c" ).getResultList();
72-
for ( Iterator iter = customers.iterator(); iter.hasNext() ; ) {
73-
Customer c = (Customer) iter.next();
74-
assertEquals( c.getSalesperson().getName(), "Mark" );
75-
}
76-
assertEquals( customers.size(), 1 );
77-
manager.getTransaction().commit();
73+
entityManager.getTransaction().begin();
74+
customers = entityManager.createQuery( "select c from Customer c" ).getResultList();
75+
for ( Object customer : customers ) {
76+
Customer c = (Customer) customer;
77+
assertEquals( "Mark", c.getSalesperson().getName() );
78+
}
79+
assertEquals( 1, customers.size() );
80+
entityManager.getTransaction().commit();
7881

79-
manager.getTransaction().begin();
80-
mark = manager.find( Employee.class, Long.valueOf( ids[0] ) );
81-
joe = manager.find( Customer.class, Long.valueOf( ids[1] ) );
82-
yomomma = manager.find( Person.class, Long.valueOf( ids[2] ) );
82+
entityManager.getTransaction().begin();
83+
mark = entityManager.find( Employee.class, ids[0] );
84+
joe = entityManager.find( Customer.class, ids[1] );
85+
yomomma = entityManager.find( Person.class, ids[2] );
8386

84-
mark.setZip( "30306" );
85-
assertEquals( 1, manager.createQuery( "select p from Person p where p.zip = '30306'" ).getResultList().size() );
86-
manager.remove( mark );
87-
manager.remove( joe );
88-
manager.remove( yomomma );
89-
assertTrue( manager.createQuery( "select p from Person p" ).getResultList().isEmpty() );
90-
manager.getTransaction().commit();
91-
manager.close();
87+
mark.setZip( "30306" );
88+
assertEquals( 1, entityManager.createQuery( "select p from Person p where p.zip = '30306'" ).getResultList().size() );
89+
entityManager.remove( mark );
90+
entityManager.remove( joe );
91+
entityManager.remove( yomomma );
92+
assertTrue( entityManager.createQuery( "select p from Person p" ).getResultList().isEmpty() );
93+
entityManager.getTransaction().commit();
94+
} );
9295
}
9396

94-
@Override
95-
public Class[] getAnnotatedClasses() {
96-
return new Class[]{
97-
Customer.class,
98-
Employee.class,
99-
Person.class
100-
};
101-
}
10297
}

hibernate-core/src/test/java/org/hibernate/orm/test/jpa/callbacks/PrivateConstructorEnhancerTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void testFindEntity(SessionFactoryScope scope) {
5858
try {
5959
Country country = session.find( Country.class, this.country.id );
6060

61-
assertNotNull( "Romania", country.getName() );
61+
assertNotNull( country.getName(), "Romania" );
6262
fail( "Should have thrown exception" );
6363
}
6464
catch (Exception expected) {
@@ -73,7 +73,7 @@ public void testGetReferenceEntity(SessionFactoryScope scope) {
7373
try {
7474
Country country = session.getReference( Country.class, this.country.id );
7575

76-
assertNotNull( "Romania", country.getName() );
76+
assertNotNull( country.getName(), "Romania" );
7777
fail( "Should have thrown exception" );
7878
}
7979
catch (Exception expected) {
@@ -88,7 +88,7 @@ public void testLoadProxyAssociation(SessionFactoryScope scope) {
8888
try {
8989
Person person = session.find( Person.class, this.person.id );
9090

91-
assertNotNull( "Romania", person.getCountry().getName() );
91+
assertNotNull( person.getCountry().getName(), "Romania" );
9292
fail( "Should have thrown exception" );
9393
}
9494
catch (Exception expected) {
@@ -101,7 +101,7 @@ public void testLoadProxyAssociation(SessionFactoryScope scope) {
101101
public void testListEntity(SessionFactoryScope scope) {
102102
scope.inTransaction( session -> {
103103
try {
104-
List<Person> persons = session.createQuery( "select p from Person p" ).getResultList();
104+
List<Person> persons = session.createQuery( "select p from Person p", Person.class ).getResultList();
105105
assertTrue( persons.stream().anyMatch( p -> p.getCountry().getName().equals( "Romania" ) ) );
106106

107107
fail( "Should have thrown exception" );
@@ -116,7 +116,7 @@ public void testListEntity(SessionFactoryScope scope) {
116116
public void testListJoinFetchEntity(SessionFactoryScope scope) {
117117
scope.inTransaction( session -> {
118118
try {
119-
List<Person> persons = session.createQuery( "select p from Person p join fetch p.country" )
119+
List<Person> persons = session.createQuery( "select p from Person p join fetch p.country", Person.class )
120120
.getResultList();
121121
assertTrue( persons.stream().anyMatch( p -> p.getCountry().getName().equals( "Romania" ) ) );
122122

hibernate-core/src/test/java/org/hibernate/orm/test/jpa/cascade/multicircle/MultiCircleJpaCascadeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import org.junit.jupiter.api.BeforeEach;
1616
import org.junit.jupiter.api.Test;
1717

18-
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
18+
import static org.hibernate.testing.orm.junit.ExtraAssertions.assertTyping;
1919
import static org.junit.jupiter.api.Assertions.assertEquals;
2020
import static org.junit.jupiter.api.Assertions.assertTrue;
2121
import static org.junit.jupiter.api.Assertions.assertSame;

hibernate-core/src/test/java/org/hibernate/orm/test/jpa/cascade/multilevel/MultiLevelCascadeCollectionEmbeddableTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import jakarta.persistence.SequenceGenerator;
2525
import jakarta.persistence.Table;
2626

27-
import org.hibernate.testing.FailureExpected;
2827
import org.hibernate.testing.orm.junit.JiraKey;
2928
import org.hibernate.testing.orm.junit.ImplicitListAsBagProvider;
3029
import org.hibernate.testing.orm.junit.Jpa;
@@ -70,7 +69,6 @@ protected void initialize(EntityManagerFactoryScope scope) {
7069
}
7170

7271
@Test
73-
@FailureExpected( jiraKey = "HHH-12291" )
7472
public void testHibernateDeleteEntityWithoutInitializingCollections(EntityManagerFactoryScope scope) {
7573
if ( !initialized ) {
7674
initialize(scope);

hibernate-core/src/test/java/org/hibernate/orm/test/jpa/cascade/multilevel/MultiLevelCascadeCollectionIdClassTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import jakarta.persistence.SequenceGenerator;
2424
import jakarta.persistence.Table;
2525

26-
import org.hibernate.testing.FailureExpected;
2726
import org.hibernate.testing.orm.junit.JiraKey;
2827
import org.hibernate.testing.orm.junit.ImplicitListAsBagProvider;
2928
import org.hibernate.testing.orm.junit.Jpa;
@@ -72,7 +71,6 @@ protected void initialize(EntityManagerFactoryScope scope) {
7271
}
7372

7473
@Test
75-
@FailureExpected( jiraKey = "HHH-12291" )
7674
public void testHibernateDeleteEntityWithoutInitializingCollections(EntityManagerFactoryScope scope) {
7775
if ( !initialized ) {
7876
initialize(scope);

0 commit comments

Comments
 (0)