Skip to content

Commit 3f2426c

Browse files
committed
HHH-19846 Drop JUnit 4 usage
1 parent 4212bc2 commit 3f2426c

File tree

13 files changed

+327
-315
lines changed

13 files changed

+327
-315
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/loader/LoaderWithInvalidQueryTest.java

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,60 +8,59 @@
88
import jakarta.persistence.Entity;
99
import jakarta.persistence.GeneratedValue;
1010
import jakarta.persistence.Id;
11-
1211
import org.hibernate.HibernateException;
1312
import org.hibernate.annotations.HQLSelect;
1413
import org.hibernate.annotations.NamedQuery;
15-
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
16-
14+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
15+
import org.hibernate.testing.orm.junit.Jpa;
1716
import org.hibernate.testing.util.ExceptionUtil;
18-
import org.junit.Test;
17+
import org.junit.jupiter.api.Test;
18+
19+
import static org.assertj.core.api.Assertions.assertThat;
20+
import static org.assertj.core.api.Fail.fail;
21+
import static org.junit.jupiter.api.Assertions.assertThrows;
1922

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertTrue;
2223

2324
/**
2425
* @author Vlad Mihalcea
2526
*/
26-
public class LoaderWithInvalidQueryTest extends BaseEntityManagerFunctionalTestCase {
27-
28-
@Override
29-
protected Class<?>[] getAnnotatedClasses() {
30-
return new Class<?>[] {
31-
Person.class
32-
};
33-
}
34-
35-
@Override
36-
public void buildEntityManagerFactory() {
37-
try {
38-
super.buildEntityManagerFactory();
39-
}
40-
catch (Exception expected) {
41-
HibernateException rootCause = (HibernateException) ExceptionUtil.rootCause( expected );
42-
Throwable[] suppressed = rootCause.getSuppressed();
43-
assertEquals( 2, suppressed.length );
44-
assertTrue( ExceptionUtil.rootCause( suppressed[0] ).getMessage().contains( "Could not resolve root entity '_Person'" ) );
45-
assertTrue( ExceptionUtil.rootCause( suppressed[1] ).getMessage().contains( "Could not resolve attribute 'valid'" ) );
27+
@Jpa(
28+
annotatedClasses = {
29+
LoaderWithInvalidQueryTest.Person.class
4630
}
47-
}
31+
)
32+
public class LoaderWithInvalidQueryTest {
33+
4834

4935
@Test
50-
public void test() {
36+
public void test(EntityManagerFactoryScope scope) {
37+
Exception expected = assertThrows( Exception.class, () -> scope.inTransaction(
38+
session -> {
39+
fail("Exception expected during the build of the EntityManagerFactory ");
40+
}
41+
) );
42+
43+
HibernateException rootCause = (HibernateException) ExceptionUtil.rootCause( expected );
44+
Throwable[] suppressed = rootCause.getSuppressed();
45+
assertThat( suppressed.length ).isEqualTo( 2 );
46+
assertThat( ExceptionUtil.rootCause( suppressed[0] ).getMessage() )
47+
.contains( "Could not resolve root entity '_Person'" );
48+
assertThat( ExceptionUtil.rootCause( suppressed[1] ).getMessage() )
49+
.contains( "Could not resolve attribute 'valid'" );
5150
}
5251

5352

5453
@Entity(name = "Person")
5554
@HQLSelect(
56-
query = "SELECT p " +
57-
"FROM Person p " +
58-
"WHERE p.id = ?1 and p.valid = true"
55+
query = "SELECT p " +
56+
"FROM Person p " +
57+
"WHERE p.id = ?1 and p.valid = true"
5958
)
6059
@NamedQuery(
61-
name = "another_invalid_sql",
62-
query = "SELECT p " +
63-
"FROM _Person p " +
64-
"WHERE p.id = ?1"
60+
name = "another_invalid_sql",
61+
query = "SELECT p " +
62+
"FROM _Person p " +
63+
"WHERE p.id = ?1"
6564
)
6665
public static class Person {
6766

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/lob/AbstractLobTest.java

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,20 @@
44
*/
55
package org.hibernate.orm.test.annotations.lob;
66

7-
import org.hibernate.dialect.*;
8-
import org.junit.Test;
97

10-
import org.hibernate.testing.SkipForDialect;
11-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
8+
import org.hibernate.dialect.SybaseDialect;
9+
import org.hibernate.testing.orm.junit.SessionFactory;
10+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
11+
import org.hibernate.testing.orm.junit.SkipForDialect;
12+
import org.junit.jupiter.api.Test;
1213

13-
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
14-
import static org.junit.Assert.assertEquals;
15-
import static org.junit.Assert.assertNotNull;
16-
import static org.junit.Assert.assertNull;
14+
import static org.assertj.core.api.Assertions.assertThat;
1715

1816
/**
1917
* @author Gail Badner
2018
*/
21-
public abstract class AbstractLobTest<B extends AbstractBook, C extends AbstractCompiledCode>
22-
extends BaseCoreFunctionalTestCase {
19+
@SessionFactory
20+
public abstract class AbstractLobTest<B extends AbstractBook, C extends AbstractCompiledCode> {
2321

2422
protected abstract Class<B> getBookClass();
2523

@@ -41,102 +39,103 @@ protected C createCompiledCode() {
4139
return getCompiledCodeClass().newInstance();
4240
}
4341
catch (Exception ex) {
44-
throw new RuntimeException( "Could not create an instance of type " + getCompiledCodeClass().getName(), ex );
42+
throw new RuntimeException( "Could not create an instance of type " + getCompiledCodeClass().getName(),
43+
ex );
4544
}
4645
}
4746

4847
protected abstract Integer getId(C compiledCode);
4948

5049
@Test
51-
public void testSerializableToBlob() throws Exception {
50+
public void testSerializableToBlob(SessionFactoryScope scope) {
5251
B book = createBook();
5352
Editor editor = new Editor();
5453
editor.setName( "O'Reilly" );
5554
book.setEditor( editor );
56-
book.setCode2( new char[] { 'r' } );
55+
book.setCode2( new char[] {'r'} );
5756

58-
doInHibernate( this::sessionFactory, session -> {
59-
session.persist( book );
60-
} );
57+
scope.inTransaction( session ->
58+
session.persist( book )
59+
);
6160

62-
doInHibernate( this::sessionFactory, session -> {
61+
scope.inTransaction( session -> {
6362
B loadedBook = getBookClass().cast( session.get( getBookClass(), getId( book ) ) );
64-
assertNotNull( loadedBook.getEditor() );
65-
assertEquals( book.getEditor().getName(), loadedBook.getEditor().getName() );
63+
assertThat( loadedBook.getEditor() ).isNotNull();
64+
assertThat( loadedBook.getEditor().getName() ).isEqualTo( book.getEditor().getName() );
6665
loadedBook.setEditor( null );
6766
} );
6867

69-
doInHibernate( this::sessionFactory, session -> {
68+
scope.inTransaction( session -> {
7069
B loadedBook = getBookClass().cast( session.get( getBookClass(), getId( book ) ) );
71-
assertNull( loadedBook.getEditor() );
70+
assertThat( loadedBook.getEditor() ).isNull();
7271
} );
7372
}
7473

7574
@Test
76-
public void testClob() throws Exception {
75+
public void testClob(SessionFactoryScope scope) {
7776

7877
B book = createBook();
7978
book.setShortDescription( "Hibernate Bible" );
8079
book.setFullText( "Hibernate in Action aims to..." );
81-
book.setCode( new Character[] { 'a', 'b', 'c' } );
82-
book.setCode2( new char[] { 'a', 'b', 'c' } );
80+
book.setCode( new Character[] {'a', 'b', 'c'} );
81+
book.setCode2( new char[] {'a', 'b', 'c'} );
8382

84-
doInHibernate( this::sessionFactory, session -> {
85-
session.persist( book );
86-
} );
83+
scope.inTransaction( session ->
84+
session.persist( book )
85+
);
8786

88-
doInHibernate( this::sessionFactory, session -> {
87+
scope.inTransaction( session -> {
8988
B b2 = getBookClass().cast( session.get( getBookClass(), getId( book ) ) );
90-
assertNotNull( b2 );
91-
assertEquals( b2.getFullText(), book.getFullText() );
92-
assertEquals( b2.getCode()[1].charValue(), book.getCode()[1].charValue() );
93-
assertEquals( b2.getCode2()[2], book.getCode2()[2] );
89+
assertThat( b2 ).isNotNull();
90+
assertThat( b2.getFullText() ).isEqualTo( book.getFullText() );
91+
assertThat( b2.getCode()[1].charValue() ).isEqualTo( book.getCode()[1].charValue() );
92+
assertThat( b2.getCode2()[2] ).isEqualTo( book.getCode2()[2] );
9493
} );
9594
}
9695

9796
@Test
98-
public void testBlob() throws Exception {
97+
public void testBlob(SessionFactoryScope scope) {
9998

10099
C cc = createCompiledCode();
101100
Byte[] header = new Byte[2];
102-
header[0] = new Byte( ( byte ) 3 );
103-
header[1] = new Byte( ( byte ) 0 );
101+
header[0] = 3;
102+
header[1] = 0;
104103
cc.setHeader( header );
105104
int codeSize = 5;
106105
byte[] full = new byte[codeSize];
107106
for ( int i = 0; i < codeSize; i++ ) {
108-
full[i] = ( byte ) ( 1 + i );
107+
full[i] = (byte) (1 + i);
109108
}
110109
cc.setFullCode( full );
111110

112-
doInHibernate( this::sessionFactory, session -> {
113-
session.persist( cc );
114-
} );
111+
scope.inTransaction( session ->
112+
session.persist( cc )
113+
);
115114

116-
doInHibernate( this::sessionFactory, session -> {
115+
scope.inTransaction( session -> {
117116
C recompiled = getCompiledCodeClass().cast( session.get( getCompiledCodeClass(), getId( cc ) ) );
118-
assertEquals( recompiled.getHeader()[1], cc.getHeader()[1] );
119-
assertEquals( recompiled.getFullCode()[codeSize - 1], cc.getFullCode()[codeSize - 1] );
117+
assertThat( recompiled.getHeader()[1] ).isEqualTo( cc.getHeader()[1] );
118+
assertThat( recompiled.getFullCode()[codeSize - 1] ).isEqualTo( cc.getFullCode()[codeSize - 1] );
120119
} );
121120
}
122121

123122
@Test
124-
@SkipForDialect( SybaseDialect.class )
125-
public void testBinary() throws Exception {
123+
@SkipForDialect(dialectClass = SybaseDialect.class)
124+
public void testBinary(SessionFactoryScope scope) {
126125

127126
C cc = createCompiledCode();
128127
byte[] metadata = new byte[2];
129-
metadata[0] = ( byte ) 3;
130-
metadata[1] = ( byte ) 0;
128+
metadata[0] = 3;
129+
metadata[1] = 0;
131130
cc.setMetadata( metadata );
132131

133-
doInHibernate( this::sessionFactory, session -> {
134-
session.persist( cc );
135-
} );
132+
scope.inTransaction( session ->
133+
session.persist( cc )
134+
);
136135

137-
doInHibernate( this::sessionFactory, session -> {
136+
scope.inTransaction( session -> {
138137
C recompiled = getCompiledCodeClass().cast( session.get( getCompiledCodeClass(), getId( cc ) ) );
139-
assertEquals( recompiled.getMetadata()[1], cc.getMetadata()[1] );
138+
assertThat( recompiled.getMetadata()[1] ).isEqualTo( cc.getMetadata()[1] );
140139
} );
141140
}
142141
}

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/lob/Dog.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright Red Hat Inc. and Hibernate Authors
44
*/
55
package org.hibernate.orm.test.annotations.lob;
6+
67
import java.io.Serializable;
78

89
public class Dog implements Serializable {

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/lob/Editor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright Red Hat Inc. and Hibernate Authors
44
*/
55
package org.hibernate.orm.test.annotations.lob;
6+
67
import java.io.Serializable;
78

89
/**

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/lob/ImageHolder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright Red Hat Inc. and Hibernate Authors
44
*/
55
package org.hibernate.orm.test.annotations.lob;
6+
67
import java.sql.Types;
78

89
import org.hibernate.annotations.JdbcTypeCode;

0 commit comments

Comments
 (0)