Skip to content

Commit f1ac4e3

Browse files
committed
HHH-19846 Drop JUnit 4 usage
1 parent 18f7793 commit f1ac4e3

File tree

2 files changed

+155
-140
lines changed

2 files changed

+155
-140
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/graph/AbstractEntityGraphTest.java

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,69 +4,69 @@
44
*/
55
package org.hibernate.orm.test.graph;
66

7-
import java.util.Collection;
8-
import java.util.List;
9-
import java.util.Map;
107
import jakarta.persistence.AttributeNode;
118
import jakarta.persistence.EntityGraph;
12-
import jakarta.persistence.EntityManager;
139
import jakarta.persistence.Subgraph;
14-
1510
import org.hibernate.graph.GraphParser;
1611
import org.hibernate.graph.spi.RootGraphImplementor;
17-
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
12+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
13+
import org.hibernate.testing.orm.junit.Jpa;
1814

19-
import org.junit.Assert;
15+
import java.util.Collection;
16+
import java.util.List;
17+
import java.util.Map;
2018

21-
public abstract class AbstractEntityGraphTest extends BaseEntityManagerFunctionalTestCase {
19+
import static org.assertj.core.api.Assertions.assertThat;
20+
import static org.junit.jupiter.api.Assertions.fail;
2221

23-
public AbstractEntityGraphTest() {
24-
super();
25-
}
2622

27-
@Override
28-
protected Class<?>[] getAnnotatedClasses() {
29-
return new Class[]{ GraphParsingTestEntity.class, GraphParsingTestSubentity.class };
30-
}
23+
@Jpa(
24+
annotatedClasses = {
25+
GraphParsingTestEntity.class,
26+
GraphParsingTestSubentity.class
27+
}
28+
)
29+
public abstract class AbstractEntityGraphTest {
3130

32-
protected <T> RootGraphImplementor<T> parseGraph(Class<T> entityType, String graphString) {
33-
EntityManager entityManager = getOrCreateEntityManager();
34-
return (RootGraphImplementor<T>) GraphParser.parse( entityType, graphString, entityManager );
31+
protected <T> RootGraphImplementor<T> parseGraph(Class<T> entityType, String graphString, EntityManagerFactoryScope scope) {
32+
return scope.fromEntityManager( entityManager ->
33+
(RootGraphImplementor<T>) GraphParser.parse( entityType, graphString, entityManager )
34+
);
3535
}
3636

37-
protected <T> RootGraphImplementor<GraphParsingTestEntity> parseGraph(String graphString) {
38-
return parseGraph( GraphParsingTestEntity.class, graphString );
37+
protected <T> RootGraphImplementor<GraphParsingTestEntity> parseGraph(String graphString, EntityManagerFactoryScope scope) {
38+
return parseGraph( GraphParsingTestEntity.class, graphString, scope );
3939
}
4040

4141
private <C extends Collection<?>> void assertNullOrEmpty(C collection) {
4242
if ( collection != null ) {
43-
Assert.assertEquals( 0, collection.size() );
43+
assertThat( collection).hasSize( 0 );
4444
}
4545
}
4646

4747
protected <M extends Map<?, ?>> void assertNullOrEmpty(M map) {
4848
if ( map != null ) {
49-
Assert.assertEquals( 0, map.size() );
49+
assertThat( map.size()).isEqualTo( 0 );
5050
}
5151
}
5252

5353
protected void assertBasicAttributes(EntityGraph<?> graph, String... names) {
54-
Assert.assertNotNull( graph );
54+
assertThat( graph ).isNotNull();
5555
assertBasicAttributes( graph.getAttributeNodes(), names );
5656
}
5757

5858
protected void assertBasicAttributes(Subgraph<?> graph, String... names) {
59-
Assert.assertNotNull( graph );
59+
assertThat( graph ).isNotNull();
6060
assertBasicAttributes( graph.getAttributeNodes(), names );
6161
}
6262

6363
private void assertBasicAttributes(List<AttributeNode<?>> attrs, String... names) {
64-
if ( ( names == null ) || ( names.length == 0 ) ) {
64+
if ( (names == null) || (names.length == 0) ) {
6565
assertNullOrEmpty( attrs );
6666
}
6767
else {
68-
Assert.assertNotNull( attrs );
69-
Assert.assertTrue( names.length <= attrs.size() );
68+
assertThat( attrs ).isNotNull();
69+
assertThat( names.length).isLessThanOrEqualTo( attrs.size() );
7070

7171
for ( String name : names ) {
7272
AttributeNode<?> node = null;
@@ -76,7 +76,7 @@ private void assertBasicAttributes(List<AttributeNode<?>> attrs, String... names
7676
break;
7777
}
7878
}
79-
Assert.assertNotNull( node );
79+
assertThat( node ).isNotNull();
8080
assertNullOrEmpty( node.getKeySubgraphs() );
8181
assertNullOrEmpty( node.getSubgraphs() );
8282
}
@@ -93,11 +93,13 @@ protected AttributeNode<?> getAttributeNodeByName(Subgraph<?> graph, String name
9393

9494
private AttributeNode<?> getAttributeNodeByName(List<AttributeNode<?>> attrs, String name, boolean required) {
9595
for ( AttributeNode<?> attr : attrs ) {
96-
if ( name.equals( attr.getAttributeName() ) )
96+
if ( name.equals( attr.getAttributeName() ) ) {
9797
return attr;
98+
}
99+
}
100+
if ( required ) {
101+
fail( "Required attribute not found." );
98102
}
99-
if ( required )
100-
Assert.fail( "Required attribute not found." );
101103
return null;
102104
}
103105

0 commit comments

Comments
 (0)