Skip to content

Commit 108cbb5

Browse files
committed
HHH-19846 - Remove JUnit4: org.hibernate.orm.test.actionqueue
Signed-off-by: Jan Schatteman <[email protected]>
1 parent c3a25c0 commit 108cbb5

File tree

2 files changed

+62
-86
lines changed

2 files changed

+62
-86
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/actionqueue/CustomAfterCompletionTest.java

Lines changed: 32 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -10,63 +10,58 @@
1010
import jakarta.persistence.Id;
1111

1212
import org.hibernate.HibernateException;
13-
import org.hibernate.action.spi.AfterTransactionCompletionProcess;
14-
import org.hibernate.engine.spi.SharedSessionContractImplementor;
1513

14+
import org.hibernate.testing.orm.junit.DomainModel;
1615
import org.hibernate.testing.orm.junit.JiraKey;
17-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
18-
import org.junit.Assert;
19-
import org.junit.Test;
16+
import org.hibernate.testing.orm.junit.SessionFactory;
17+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
18+
import org.junit.jupiter.api.AfterEach;
19+
import org.junit.jupiter.api.Assertions;
20+
import org.junit.jupiter.api.Test;
2021

2122
import static org.hamcrest.CoreMatchers.containsString;
2223
import static org.hamcrest.CoreMatchers.instanceOf;
23-
import static org.junit.Assert.assertEquals;
24-
import static org.junit.Assert.assertThat;
24+
import static org.hamcrest.MatcherAssert.assertThat;
25+
import static org.junit.jupiter.api.Assertions.assertEquals;
2526

26-
public class CustomAfterCompletionTest extends BaseCoreFunctionalTestCase {
27+
@DomainModel(annotatedClasses = {CustomAfterCompletionTest.SimpleEntity.class})
28+
@SessionFactory
29+
public class CustomAfterCompletionTest {
30+
31+
@AfterEach
32+
public void cleanup(SessionFactoryScope scope) {
33+
scope.inTransaction( session -> session.getSessionFactory().getSchemaManager().truncate() );
34+
}
2735

2836
@Test
2937
@JiraKey(value = "HHH-13666")
30-
public void success() {
31-
inSession( session -> {
38+
public void success(SessionFactoryScope scope) {
39+
scope.inSession( session -> {
3240
AtomicBoolean called = new AtomicBoolean( false );
33-
session.getActionQueue().registerCallback( new AfterTransactionCompletionProcess() {
34-
@Override
35-
public void doAfterTransactionCompletion(boolean success, SharedSessionContractImplementor session) {
36-
called.set( true );
37-
}
38-
} );
39-
Assert.assertFalse( called.get() );
40-
inTransaction( session, theSession -> {
41-
theSession.persist( new SimpleEntity( "jack" ) );
42-
} );
43-
Assert.assertTrue( called.get() );
41+
session.getActionQueue().registerCallback(
42+
(success, session1) -> called.set(true) );
43+
Assertions.assertFalse( called.get() );
44+
scope.inTransaction( session, theSession -> theSession.persist(new SimpleEntity("jack")) );
45+
Assertions.assertTrue( called.get() );
4446
} );
4547

4648
// Check that the transaction was committed
47-
inTransaction( session -> {
48-
long count = session.createQuery( "select count(*) from SimpleEntity", Long.class )
49-
.uniqueResult();
49+
scope.inTransaction( session -> {
50+
long count = session.createQuery( "select count(*) from SimpleEntity", Long.class ).uniqueResult();
5051
assertEquals( 1L, count );
5152
} );
5253
}
5354

5455
@Test
5556
@JiraKey(value = "HHH-13666")
56-
public void failure() {
57+
public void failure(SessionFactoryScope scope) {
5758
try {
58-
inSession( session -> {
59-
session.getActionQueue().registerCallback( new AfterTransactionCompletionProcess() {
60-
@Override
61-
public void doAfterTransactionCompletion(boolean success, SharedSessionContractImplementor session) {
62-
throw new RuntimeException( "My exception" );
63-
}
64-
} );
65-
inTransaction( session, theSession -> {
66-
theSession.persist( new SimpleEntity( "jack" ) );
67-
} );
59+
scope.inSession( session -> {
60+
session.getActionQueue().registerCallback(
61+
(success, session1) -> {throw new RuntimeException( "My exception" );} );
62+
scope.inTransaction( session, theSession -> theSession.persist(new SimpleEntity("jack")) );
6863
} );
69-
Assert.fail( "Expected exception to be thrown" );
64+
Assertions.fail( "Expected exception to be thrown" );
7065
}
7166
catch (Exception e) {
7267
assertThat( e, instanceOf( HibernateException.class ) );
@@ -80,23 +75,13 @@ public void doAfterTransactionCompletion(boolean success, SharedSessionContractI
8075
}
8176

8277
// Check that the transaction was committed
83-
inTransaction( session -> {
78+
scope.inTransaction( session -> {
8479
long count = session.createQuery( "select count(*) from SimpleEntity", Long.class )
8580
.uniqueResult();
8681
assertEquals( 1L, count );
8782
} );
8883
}
8984

90-
@Override
91-
protected Class<?>[] getAnnotatedClasses() {
92-
return new Class<?>[] { SimpleEntity.class };
93-
}
94-
95-
@Override
96-
protected boolean isCleanupTestDataRequired() {
97-
return true;
98-
}
99-
10085
@Entity(name = "SimpleEntity")
10186
public static class SimpleEntity {
10287
@Id

hibernate-core/src/test/java/org/hibernate/orm/test/actionqueue/CustomBeforeCompletionTest.java

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,42 @@
1010
import jakarta.persistence.Id;
1111

1212
import org.hibernate.HibernateException;
13-
import org.hibernate.action.spi.BeforeTransactionCompletionProcess;
1413

15-
import org.hibernate.engine.spi.SharedSessionContractImplementor;
14+
import org.hibernate.testing.orm.junit.DomainModel;
1615
import org.hibernate.testing.orm.junit.JiraKey;
17-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
18-
import org.junit.Assert;
19-
import org.junit.Test;
16+
import org.hibernate.testing.orm.junit.SessionFactory;
17+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
18+
import org.junit.jupiter.api.AfterEach;
19+
import org.junit.jupiter.api.Assertions;
20+
import org.junit.jupiter.api.Test;
2021

2122
import static org.hamcrest.CoreMatchers.containsString;
2223
import static org.hamcrest.CoreMatchers.instanceOf;
23-
import static org.junit.Assert.assertEquals;
24-
import static org.junit.Assert.assertThat;
24+
import static org.hamcrest.MatcherAssert.assertThat;
25+
import static org.junit.jupiter.api.Assertions.assertEquals;
2526

26-
public class CustomBeforeCompletionTest extends BaseCoreFunctionalTestCase {
27+
@DomainModel(annotatedClasses = {CustomBeforeCompletionTest.SimpleEntity.class})
28+
@SessionFactory
29+
public class CustomBeforeCompletionTest {
30+
31+
@AfterEach
32+
public void cleanup(SessionFactoryScope scope) {
33+
scope.inTransaction( session -> session.getSessionFactory().getSchemaManager().truncate() );
34+
}
2735

2836
@Test
2937
@JiraKey(value = "HHH-13666")
30-
public void success() {
31-
inSession( session -> {
38+
public void success(SessionFactoryScope scope) {
39+
scope.inSession( session -> {
3240
AtomicBoolean called = new AtomicBoolean( false );
33-
session.getActionQueue().registerCallback( s -> called.set( true ) );
34-
Assert.assertFalse( called.get() );
35-
inTransaction( session, theSession -> {
36-
theSession.persist( new SimpleEntity( "jack" ) );
37-
} );
38-
Assert.assertTrue( called.get() );
41+
session.getActionQueue().registerCallback( s -> called.set(true) );
42+
Assertions.assertFalse( called.get() );
43+
scope.inTransaction( session, theSession -> theSession.persist(new SimpleEntity("jack")) );
44+
Assertions.assertTrue( called.get() );
3945
} );
4046

4147
// Check that the transaction was committed
42-
inTransaction( session -> {
48+
scope.inTransaction( session -> {
4349
long count = session.createQuery( "select count(*) from SimpleEntity", Long.class )
4450
.uniqueResult();
4551
assertEquals( 1L, count );
@@ -48,20 +54,15 @@ public void success() {
4854

4955
@Test
5056
@JiraKey(value = "HHH-13666")
51-
public void failure() {
57+
public void failure(SessionFactoryScope scope) {
5258
try {
53-
inSession( session -> {
54-
session.getActionQueue().registerCallback( new BeforeTransactionCompletionProcess() {
55-
@Override
56-
public void doBeforeTransactionCompletion(SharedSessionContractImplementor session) {
57-
throw new RuntimeException( "My exception" );
58-
}
59-
} );
60-
inTransaction( session, theSession -> {
61-
theSession.persist( new SimpleEntity( "jack" ) );
59+
scope.inSession( session -> {
60+
session.getActionQueue().registerCallback( session1 -> {
61+
throw new RuntimeException( "My exception" );
6262
} );
63+
scope.inTransaction( session, theSession -> theSession.persist(new SimpleEntity("jack")) );
6364
} );
64-
Assert.fail( "Expected exception to be thrown" );
65+
Assertions.fail( "Expected exception to be thrown" );
6566
}
6667
catch (Exception e) {
6768
assertThat( e, instanceOf( HibernateException.class ) );
@@ -75,23 +76,13 @@ public void doBeforeTransactionCompletion(SharedSessionContractImplementor sessi
7576
}
7677

7778
// Check that the transaction was rolled back
78-
inTransaction( session -> {
79+
scope.inTransaction( session -> {
7980
long count = session.createQuery( "select count(*) from SimpleEntity", Long.class )
8081
.uniqueResult();
8182
assertEquals( 0L, count );
8283
} );
8384
}
8485

85-
@Override
86-
protected Class<?>[] getAnnotatedClasses() {
87-
return new Class<?>[] { SimpleEntity.class };
88-
}
89-
90-
@Override
91-
protected boolean isCleanupTestDataRequired() {
92-
return true;
93-
}
94-
9586
@Entity(name = "SimpleEntity")
9687
public static class SimpleEntity {
9788
@Id

0 commit comments

Comments
 (0)