Skip to content

Commit a129e23

Browse files
committed
HHH-19846 Drop JUnit 4 usage
1 parent 08fc1fd commit a129e23

File tree

3 files changed

+172
-193
lines changed

3 files changed

+172
-193
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/sql/hand/identity/CustomInsertSQLWithIdentityColumnTest.java

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,42 @@
44
*/
55
package org.hibernate.orm.test.sql.hand.identity;
66

7-
import org.junit.Test;
87

98
import org.hibernate.JDBCException;
10-
import org.hibernate.Session;
119
import org.hibernate.orm.test.sql.hand.Organization;
12-
import org.hibernate.testing.DialectChecks;
13-
import org.hibernate.testing.RequiresDialectFeature;
14-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
10+
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
11+
import org.hibernate.testing.orm.junit.DomainModel;
12+
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
13+
import org.hibernate.testing.orm.junit.SessionFactory;
14+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
15+
import org.junit.jupiter.api.Test;
16+
17+
import static org.junit.jupiter.api.Assertions.assertThrows;
1518

16-
import static org.junit.Assert.fail;
1719

1820
/**
1921
* Custom SQL tests for combined usage of custom insert SQL and identity columns
2022
*
2123
* @author Gail Badner
2224
*/
23-
@RequiresDialectFeature( DialectChecks.SupportsIdentityColumns.class )
24-
public class CustomInsertSQLWithIdentityColumnTest extends BaseCoreFunctionalTestCase {
25-
26-
@Override
27-
protected String getBaseForMappings() {
28-
return "org/hibernate/orm/test/";
29-
}
30-
31-
@Override
32-
public String[] getMappings() {
33-
return new String[] {"sql/hand/identity/Mappings.hbm.xml"};
34-
}
25+
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsIdentityColumns.class)
26+
@DomainModel(
27+
xmlMappings = "org/hibernate/orm/test/sql/hand/identity/Mappings.hbm.xml"
28+
)
29+
@SessionFactory
30+
public class CustomInsertSQLWithIdentityColumnTest {
3531

3632
@Test
37-
public void testBadInsertionFails() {
38-
Session session = openSession();
39-
session.beginTransaction();
40-
Organization org = new Organization( "hola!" );
41-
try {
42-
session.persist( org );
43-
session.remove( org );
44-
fail( "expecting bad custom insert statement to fail" );
45-
}
46-
catch( JDBCException e ) {
47-
// expected failure
48-
}
49-
50-
session.getTransaction().rollback();
51-
session.close();
33+
public void testBadInsertionFails(SessionFactoryScope scope) {
34+
scope.inTransaction(
35+
session -> {
36+
Organization org = new Organization( "hola!" );
37+
// expecting bad custom insert statement to fail
38+
assertThrows( JDBCException.class, () -> {
39+
session.persist( org );
40+
session.remove( org );
41+
} );
42+
}
43+
);
5244
}
5345
}

hibernate-core/src/test/java/org/hibernate/orm/test/sql/hand/quotedidentifiers/NativeSqlAndQuotedIdentifiersTest.java

Lines changed: 51 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4,96 +4,86 @@
44
*/
55
package org.hibernate.orm.test.sql.hand.quotedidentifiers;
66

7-
import org.hibernate.Session;
87
import org.hibernate.dialect.Dialect;
98
import org.hibernate.query.NativeQuery;
9+
import org.hibernate.testing.orm.junit.DialectFeatureCheck;
10+
import org.hibernate.testing.orm.junit.DomainModel;
11+
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
12+
import org.hibernate.testing.orm.junit.SessionFactory;
13+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
14+
import org.junit.jupiter.api.AfterAll;
15+
import org.junit.jupiter.api.BeforeAll;
16+
import org.junit.jupiter.api.Test;
1017

11-
import org.hibernate.testing.DialectCheck;
12-
import org.hibernate.testing.RequiresDialectFeature;
13-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
14-
import org.junit.Test;
1518

1619
/**
1720
* Test of various situations with native-sql queries and quoted identifiers
1821
*
1922
* @author Steve Ebersole
2023
*/
21-
@RequiresDialectFeature( value = NativeSqlAndQuotedIdentifiersTest.LocalDialectCheck.class )
22-
public class NativeSqlAndQuotedIdentifiersTest extends BaseCoreFunctionalTestCase {
24+
@RequiresDialectFeature(feature = NativeSqlAndQuotedIdentifiersTest.LocalDialectCheck.class)
25+
@DomainModel(
26+
xmlMappings = "org/hibernate/orm/test/sql/hand/quotedidentifiers/Mappings.hbm.xml"
27+
)
28+
@SessionFactory
29+
public class NativeSqlAndQuotedIdentifiersTest {
2330

24-
@Override
25-
protected String getBaseForMappings() {
26-
return "org/hibernate/orm/test/";
27-
}
28-
29-
@Override
30-
public String[] getMappings() {
31-
return new String[] { "sql/hand/quotedidentifiers/Mappings.hbm.xml" };
32-
}
31+
public static class LocalDialectCheck implements DialectFeatureCheck {
3332

34-
public static class LocalDialectCheck implements DialectCheck {
3533
@Override
36-
public boolean isMatch(Dialect dialect) {
34+
public boolean apply(Dialect dialect) {
3735
return '\"' == dialect.openQuote();
3836
}
3937
}
4038

41-
@Override
42-
protected void prepareTest() throws Exception {
43-
if( sessionFactory()==null)return;
44-
Session session = sessionFactory().openSession();
45-
session.beginTransaction();
46-
session.persist( new Person( "me" ) );
47-
session.getTransaction().commit();
48-
session.close();
39+
@BeforeAll
40+
protected void prepareTest(SessionFactoryScope scope) throws Exception {
41+
scope.inTransaction(
42+
session ->
43+
session.persist( new Person( "me" ) )
44+
);
4945
}
5046

51-
@Override
52-
protected void cleanupTest() throws Exception {
53-
if( sessionFactory()==null)return;
54-
Session session = sessionFactory().openSession();
55-
session.beginTransaction();
56-
session.createQuery( "delete Person" ).executeUpdate();
57-
session.getTransaction().commit();
58-
session.close();
47+
@AfterAll
48+
protected void cleanupTest(SessionFactoryScope scope) throws Exception {
49+
scope.getSessionFactory().getSchemaManager().truncateMappedObjects();
5950
}
6051

6152
@Test
62-
public void testCompleteScalarDiscovery() {
63-
Session session = openSession();
64-
session.beginTransaction();
65-
session.getNamedQuery( "query-person" ).list();
66-
session.getTransaction().commit();
67-
session.close();
53+
public void testCompleteScalarDiscovery(SessionFactoryScope scope) {
54+
scope.inTransaction(
55+
session ->
56+
session.getNamedQuery( "query-person" ).list()
57+
);
6858
}
6959

7060
@Test
71-
public void testPartialScalarDiscovery() {
72-
Session session = openSession();
73-
session.beginTransaction();
74-
NativeQuery query = session.getNamedNativeQuery( "query-person", "person-scalar" );
75-
query.list();
76-
session.getTransaction().commit();
77-
session.close();
61+
public void testPartialScalarDiscovery(SessionFactoryScope scope) {
62+
scope.inTransaction(
63+
session -> {
64+
NativeQuery query = session.getNamedNativeQuery( "query-person", "person-scalar" );
65+
query.list();
66+
}
67+
);
7868
}
7969

8070
@Test
81-
public void testBasicEntityMapping() {
82-
Session session = openSession();
83-
session.beginTransaction();
84-
NativeQuery query = session.getNamedNativeQuery( "query-person", "person-entity-basic" );
85-
query.list();
86-
session.getTransaction().commit();
87-
session.close();
71+
public void testBasicEntityMapping(SessionFactoryScope scope) {
72+
scope.inTransaction(
73+
session -> {
74+
NativeQuery query = session.getNamedNativeQuery( "query-person", "person-entity-basic" );
75+
query.list();
76+
}
77+
);
8878
}
8979

9080
@Test
91-
public void testExpandedEntityMapping() {
92-
Session session = openSession();
93-
session.beginTransaction();
94-
NativeQuery query = session.getNamedNativeQuery( "query-person", "person-entity-expanded" );
95-
query.list();
96-
session.getTransaction().commit();
97-
session.close();
81+
public void testExpandedEntityMapping(SessionFactoryScope scope) {
82+
scope.inTransaction(
83+
session -> {
84+
NativeQuery query = session.getNamedNativeQuery( "query-person", "person-entity-expanded" );
85+
query.list();
86+
}
87+
);
9888
}
9989
}

0 commit comments

Comments
 (0)