Skip to content

Commit a8fba61

Browse files
committed
HHH-19846 Drop JUnit 4 usage
1 parent 01e4ca3 commit a8fba61

File tree

6 files changed

+387
-346
lines changed

6 files changed

+387
-346
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/entitygraph/mappedbyid/LoadGraphFindByIdTest.java

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
*/
55
package org.hibernate.orm.test.entitygraph.mappedbyid;
66

7-
import java.util.HashMap;
8-
import java.util.Map;
97
import jakarta.persistence.Entity;
108
import jakarta.persistence.EntityGraph;
119
import jakarta.persistence.EntityManager;
@@ -18,31 +16,31 @@
1816
import jakarta.persistence.criteria.CriteriaBuilder;
1917
import jakarta.persistence.criteria.CriteriaQuery;
2018
import jakarta.persistence.criteria.Root;
21-
22-
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
23-
19+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
2420
import org.hibernate.testing.orm.junit.JiraKey;
25-
import org.junit.Assert;
26-
import org.junit.FixMethodOrder;
27-
import org.junit.Test;
28-
import org.junit.runners.MethodSorters;
21+
import org.hibernate.testing.orm.junit.Jpa;
22+
import org.junit.jupiter.api.BeforeAll;
23+
import org.junit.jupiter.api.Test;
24+
25+
import java.util.HashMap;
26+
import java.util.Map;
2927

30-
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
28+
import static org.assertj.core.api.Assertions.assertThat;
3129

3230
/**
3331
* @author Oliver Breidenbach
3432
*/
35-
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
36-
public class LoadGraphFindByIdTest extends BaseEntityManagerFunctionalTestCase {
37-
38-
@Override
39-
protected Class<?>[] getAnnotatedClasses() {
40-
return new Class[] {User.class, UserStatistic.class};
41-
}
42-
43-
@Override
44-
protected void afterEntityManagerFactoryBuilt() {
45-
doInJPA( this::entityManagerFactory, em -> {
33+
@Jpa(
34+
annotatedClasses = {
35+
LoadGraphFindByIdTest.User.class,
36+
LoadGraphFindByIdTest.UserStatistic.class
37+
}
38+
)
39+
public class LoadGraphFindByIdTest {
40+
41+
@BeforeAll
42+
protected void setUp(EntityManagerFactoryScope scope) {
43+
scope.inTransaction( em -> {
4644
UserStatistic statistic = new UserStatistic();
4745
statistic.id = 1L;
4846
statistic.commentCount = 7;
@@ -57,19 +55,19 @@ protected void afterEntityManagerFactoryBuilt() {
5755

5856
@Test
5957
@JiraKey(value = "HHH-10842")
60-
public void findByPrimaryKeyWithId() {
61-
doInJPA( this::entityManagerFactory, em -> {
58+
public void findByPrimaryKeyWithId(EntityManagerFactoryScope scope) {
59+
scope.inTransaction( em -> {
6260
User result = em.find( User.class, 1L, createProperties( em ) );
63-
Assert.assertNotNull( result.userStatistic.commentCount );
61+
assertThat( result.userStatistic.commentCount ).isNotNull();
6462
} );
6563
}
6664

6765
@Test
6866
@JiraKey(value = "HHH-10842")
69-
public void findByPrimaryKeyWithQuery() {
70-
doInJPA( this::entityManagerFactory, em -> {
67+
public void findByPrimaryKeyWithQuery(EntityManagerFactoryScope scope) {
68+
scope.inTransaction( em -> {
7169
User result = createTypedQuery( em ).getSingleResult();
72-
Assert.assertNotNull( result.userStatistic.commentCount );
70+
assertThat( result.userStatistic.commentCount ).isNotNull();
7371
} );
7472
}
7573

@@ -85,7 +83,7 @@ private TypedQuery<User> createTypedQuery(EntityManager em) {
8583
}
8684

8785
private Map<String, Object> createProperties(EntityManager em) {
88-
Map<String, Object> properties = new HashMap<String, Object>();
86+
Map<String, Object> properties = new HashMap<>();
8987
properties.put(
9088
"javax.persistence.loadgraph",
9189
createEntityGraph( em )

hibernate-core/src/test/java/org/hibernate/orm/test/entitygraph/parser/AbstractEntityGraphTest.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,29 @@
44
*/
55
package org.hibernate.orm.test.entitygraph.parser;
66

7-
import jakarta.persistence.EntityManager;
8-
97
import org.hibernate.graph.GraphParser;
108
import org.hibernate.graph.spi.RootGraphImplementor;
11-
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
12-
13-
public abstract class AbstractEntityGraphTest extends BaseEntityManagerFunctionalTestCase {
14-
15-
public AbstractEntityGraphTest() {
16-
super();
17-
}
18-
19-
@Override
20-
protected Class<?>[] getAnnotatedClasses() {
21-
return new Class[]{ GraphParsingTestEntity.class, GraphParsingTestSubEntity.class };
22-
}
23-
24-
protected <T> RootGraphImplementor<T> parseGraph(Class<T> entityType, String graphString) {
25-
EntityManager entityManager = getOrCreateEntityManager();
26-
return (RootGraphImplementor<T>) GraphParser.parse( entityType, graphString, entityManager );
9+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
10+
import org.hibernate.testing.orm.junit.Jpa;
11+
12+
@Jpa(
13+
annotatedClasses = {
14+
GraphParsingTestEntity.class,
15+
GraphParsingTestSubEntity.class
16+
}
17+
)
18+
public abstract class AbstractEntityGraphTest {
19+
20+
protected <T> RootGraphImplementor<T> parseGraph(Class<T> entityType, String graphString, EntityManagerFactoryScope scope) {
21+
return scope.fromEntityManager(
22+
entityManager -> {
23+
return (RootGraphImplementor<T>) GraphParser.parse( entityType, graphString, entityManager );
24+
}
25+
);
2726
}
2827

29-
protected <T> RootGraphImplementor<GraphParsingTestEntity> parseGraph(String graphString) {
30-
return parseGraph( GraphParsingTestEntity.class, graphString );
28+
protected <T> RootGraphImplementor<GraphParsingTestEntity> parseGraph(String graphString, EntityManagerFactoryScope scope) {
29+
return parseGraph( GraphParsingTestEntity.class, graphString, scope );
3130
}
3231

3332
}

hibernate-core/src/test/java/org/hibernate/orm/test/entitygraph/parser/AssertionHelper.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,47 @@
77
import jakarta.persistence.AttributeNode;
88
import jakarta.persistence.EntityGraph;
99
import jakarta.persistence.Subgraph;
10-
import org.junit.Assert;
1110

1211
import java.util.Collection;
1312
import java.util.List;
1413
import java.util.Map;
1514

15+
import static org.assertj.core.api.Assertions.assertThat;
16+
import static org.junit.jupiter.api.Assertions.fail;
17+
1618
/**
1719
* @author Steve Ebersole
1820
*/
1921
public class AssertionHelper {
2022
static <C extends Collection<?>> void assertNullOrEmpty(C collection) {
2123
if ( collection != null ) {
22-
Assert.assertEquals( 0, collection.size() );
24+
assertThat( collection ).hasSize( 0 );
2325
}
2426
}
2527

2628
public static <M extends Map<?, ?>> void assertNullOrEmpty(M map) {
2729
if ( map != null ) {
28-
Assert.assertEquals( 0, map.size() );
30+
assertThat( map.size() ).isEqualTo( 0 );
2931
}
3032
}
3133

3234
public static void assertBasicAttributes(EntityGraph<?> graph, String... names) {
33-
Assert.assertNotNull( graph );
35+
assertThat( graph ).isNotNull();
3436
assertBasicAttributes( graph.getAttributeNodes(), names );
3537
}
3638

3739
public static void assertBasicAttributes(Subgraph<?> graph, String... names) {
38-
Assert.assertNotNull( graph );
40+
assertThat( graph ).isNotNull();
3941
assertBasicAttributes( graph.getAttributeNodes(), names );
4042
}
4143

4244
public static void assertBasicAttributes(List<AttributeNode<?>> attrs, String... names) {
43-
if ( ( names == null ) || ( names.length == 0 ) ) {
45+
if ( (names == null) || (names.length == 0) ) {
4446
assertNullOrEmpty( attrs );
4547
}
4648
else {
47-
Assert.assertNotNull( attrs );
48-
Assert.assertTrue( names.length <= attrs.size() );
49+
assertThat( attrs ).isNotNull();
50+
assertThat( names.length ).isLessThanOrEqualTo( attrs.size() );
4951

5052
for ( String name : names ) {
5153
AttributeNode<?> node = null;
@@ -55,7 +57,7 @@ public static void assertBasicAttributes(List<AttributeNode<?>> attrs, String...
5557
break;
5658
}
5759
}
58-
Assert.assertNotNull( node );
60+
assertThat( node ).isNotNull();
5961
assertNullOrEmpty( node.getKeySubgraphs() );
6062
assertNullOrEmpty( node.getSubgraphs() );
6163
}
@@ -72,11 +74,13 @@ public static AttributeNode<?> getAttributeNodeByName(Subgraph<?> graph, String
7274

7375
public static AttributeNode<?> getAttributeNodeByName(List<AttributeNode<?>> attrs, String name, boolean required) {
7476
for ( AttributeNode<?> attr : attrs ) {
75-
if ( name.equals( attr.getAttributeName() ) )
77+
if ( name.equals( attr.getAttributeName() ) ) {
7678
return attr;
79+
}
80+
}
81+
if ( required ) {
82+
fail( "Required attribute not found." );
7783
}
78-
if ( required )
79-
Assert.fail( "Required attribute not found." );
8084
return null;
8185
}
8286
}

0 commit comments

Comments
 (0)