Skip to content

Commit 373eec7

Browse files
committed
HHH-19846 - Drop JUnit 4 usage
Cannot convert... * org.hibernate.orm.test.hql.PostgreSQLFunctionSelectClauseTest - registering custom function * org.hibernate.orm.test.hql.PostgreSQLFunctionWhereClauseTest - aux-db-object * org.hibernate.orm.test.id.usertype - type registrations * org.hibernate.orm.test.idgen.enhanced.HiloOptimizerConcurrencyTest - recreation of SF during tests
1 parent 2e5c662 commit 373eec7

30 files changed

+550
-625
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/idclass/IdClassHbmTest.java

Lines changed: 45 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,70 +4,60 @@
44
*/
55
package org.hibernate.orm.test.idclass;
66

7-
import org.junit.Test;
7+
import org.hibernate.testing.orm.junit.DomainModel;
8+
import org.hibernate.testing.orm.junit.ServiceRegistry;
9+
import org.hibernate.testing.orm.junit.SessionFactory;
10+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
11+
import org.hibernate.testing.orm.junit.Setting;
812

9-
import org.hibernate.Session;
10-
import org.hibernate.Transaction;
11-
import org.hibernate.cfg.AvailableSettings;
12-
import org.hibernate.cfg.Configuration;
13+
import org.junit.jupiter.api.AfterEach;
14+
import org.junit.jupiter.api.Test;
1315

14-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
15-
16-
import static org.junit.Assert.assertEquals;
16+
import static org.hibernate.cfg.MappingSettings.JPA_METAMODEL_POPULATION;
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
1718

1819
/**
1920
* @author Gavin King
2021
*/
21-
public class IdClassHbmTest extends BaseCoreFunctionalTestCase {
22-
public String[] getMappings() {
23-
return new String[] { "/org/hibernate/orm/test/idclass/Customer.hbm.xml" };
24-
}
25-
26-
@Override
27-
protected void configure(Configuration configuration) {
28-
// the Customer entity has a composite id that is not embeddable ( not supported by JPA ).
29-
configuration.setProperty( AvailableSettings.JPA_METAMODEL_POPULATION, "disabled" );
22+
@SuppressWarnings("JUnitMalformedDeclaration")
23+
@DomainModel(xmlMappings = "/org/hibernate/orm/test/idclass/Customer.hbm.xml")
24+
@ServiceRegistry(settings = @Setting(name=JPA_METAMODEL_POPULATION, value = "disabled"))
25+
@SessionFactory
26+
public class IdClassHbmTest {
27+
@AfterEach
28+
void dropTestData(SessionFactoryScope factoryScope) {
29+
factoryScope.dropData();
3030
}
3131

3232
@Test
33-
public void testIdClass() {
34-
Session s = openSession();
35-
Transaction t = s.beginTransaction();
36-
Customer cust = new FavoriteCustomer("JBoss", "RouteOne", "Detroit");
37-
s.persist(cust);
38-
t.commit();
39-
s.close();
40-
41-
s = openSession();
42-
CustomerId custId = new CustomerId("JBoss", "RouteOne");
43-
t = s.beginTransaction();
44-
cust = (Customer) s.get(Customer.class, custId);
45-
assertEquals( "Detroit", cust.getAddress() );
46-
assertEquals( cust.getCustomerName(), custId.getCustomerName() );
47-
assertEquals( cust.getOrgName(), custId.getOrgName() );
48-
t.commit();
49-
s.close();
50-
51-
s = openSession();
52-
t = s.beginTransaction();
53-
cust = (Customer) s.createQuery("from Customer where id.customerName = 'RouteOne'").uniqueResult();
54-
assertEquals( "Detroit", cust.getAddress() );
55-
assertEquals( cust.getCustomerName(), custId.getCustomerName() );
56-
assertEquals( cust.getOrgName(), custId.getOrgName() );
57-
t.commit();
58-
s.close();
59-
60-
s = openSession();
61-
t = s.beginTransaction();
62-
cust = (Customer) s.createQuery("from Customer where customerName = 'RouteOne'").uniqueResult();
63-
assertEquals( "Detroit", cust.getAddress() );
64-
assertEquals( cust.getCustomerName(), custId.getCustomerName() );
65-
assertEquals( cust.getOrgName(), custId.getOrgName() );
66-
67-
s.createQuery( "delete from Customer" ).executeUpdate();
68-
69-
t.commit();
70-
s.close();
33+
public void testIdClass(SessionFactoryScope factoryScope) {
34+
factoryScope.inTransaction( (s) -> {
35+
var customer = new FavoriteCustomer("JBoss", "RouteOne", "Detroit");
36+
s.persist(customer);
37+
} );
38+
39+
var customerId = new CustomerId("JBoss", "RouteOne");
40+
41+
factoryScope.inTransaction( (s) -> {
42+
var customer = s.find( Customer.class, customerId );
43+
assertEquals( "Detroit", customer.getAddress() );
44+
assertEquals( customerId.getCustomerName(), customer.getCustomerName() );
45+
assertEquals( customerId.getOrgName(), customer.getOrgName() );
46+
} );
47+
48+
factoryScope.inTransaction( (s) -> {
49+
var customer = s.createQuery("from Customer where id.customerName = 'RouteOne'", Customer.class).uniqueResult();
50+
assertEquals( "Detroit", customer.getAddress() );
51+
assertEquals( customerId.getCustomerName(), customer.getCustomerName() );
52+
assertEquals( customerId.getOrgName(), customer.getOrgName() );
53+
} );
54+
55+
factoryScope.inTransaction( (s) -> {
56+
var customer = s.createQuery("from Customer where customerName = 'RouteOne'", Customer.class).uniqueResult();
57+
assertEquals( "Detroit", customer.getAddress() );
58+
assertEquals( customerId.getCustomerName(), customer.getCustomerName() );
59+
assertEquals( customerId.getOrgName(), customer.getOrgName() );
60+
} );
7161
}
7262

7363
}

hibernate-core/src/test/java/org/hibernate/orm/test/idclass/JoinedSubclassWithIdClassTest.java

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,55 @@
55
package org.hibernate.orm.test.idclass;
66

77

8+
import jakarta.persistence.Entity;
9+
import jakarta.persistence.Id;
10+
import jakarta.persistence.IdClass;
11+
import jakarta.persistence.Inheritance;
12+
import jakarta.persistence.InheritanceType;
13+
import org.hibernate.testing.orm.junit.DomainModel;
14+
import org.hibernate.testing.orm.junit.JiraKey;
15+
import org.hibernate.testing.orm.junit.SessionFactory;
16+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
17+
import org.junit.jupiter.api.Test;
18+
819
import java.io.Serializable;
920
import java.util.Objects;
10-
import jakarta.persistence.*;
11-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
12-
import org.hibernate.testing.orm.junit.JiraKey;
13-
import org.junit.Test;
1421

15-
import static org.hamcrest.core.Is.is;
16-
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
17-
import static org.junit.Assert.assertThat;
22+
import static org.assertj.core.api.Assertions.assertThat;
1823

1924
/**
2025
* @author Aber Tian
2126
*/
2227
@JiraKey("HHH-16054")
23-
public class JoinedSubclassWithIdClassTest extends BaseCoreFunctionalTestCase {
24-
25-
@Override
26-
protected Class<?>[] getAnnotatedClasses() {
27-
return new Class[] {
28-
BaseEntity.class,
29-
ConcreteEntity.class
30-
};
31-
}
32-
28+
@DomainModel(annotatedClasses = {
29+
JoinedSubclassWithIdClassTest.BaseEntity.class,
30+
JoinedSubclassWithIdClassTest.ConcreteEntity.class
31+
})
32+
@SessionFactory
33+
public class JoinedSubclassWithIdClassTest {
3334
@Test
34-
public void testJoinedSubClassWithIdClassComposeKey() {
35-
36-
ConcreteEntity entity = new ConcreteEntity();
37-
entity.setId( 1L );
38-
entity.setDealer( "dealer" );
39-
entity.setName( "aber" );
40-
entity.setAge( 18 );
35+
public void testJoinedSubClassWithIdClassComposeKey(SessionFactoryScope factoryScope) {
36+
var created = factoryScope.fromTransaction( (session) -> {
37+
var entity = new ConcreteEntity();
38+
entity.setId( 1L );
39+
entity.setDealer( "dealer" );
40+
entity.setName( "aber" );
41+
entity.setAge( 18 );
42+
43+
return session.merge( entity );
44+
} );
4145

42-
Pk pk = new Pk();
43-
pk.id = 1L;
44-
pk.dealer = "dealer";
46+
factoryScope.inTransaction( (session) -> {
47+
created.setName( "tian" );
48+
session.merge( created );
4549

46-
doInHibernate( this::sessionFactory, session -> {
47-
session.merge( entity );
48-
} );
50+
var pk = new Pk();
51+
pk.id = 1L;
52+
pk.dealer = "dealer";
4953

50-
doInHibernate( this::sessionFactory, session -> {
51-
entity.setName( "tian" );
52-
session.merge( entity );
53-
BaseEntity baseEntity = session.find( BaseEntity.class, pk );
54-
assertThat( baseEntity.name, is( "tian" ) );
54+
var baseEntity = session.find( BaseEntity.class, pk );
55+
assertThat( baseEntity.name ).isEqualTo( "tian" );
5556
} );
56-
5757
}
5858

5959
public static class Pk implements Serializable {

hibernate-core/src/test/java/org/hibernate/orm/test/idgen/IdGeneratorNameScopingTest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
import org.hibernate.testing.orm.junit.DomainModel;
1919
import org.hibernate.testing.orm.junit.SessionFactory;
2020
import org.hibernate.testing.util.ServiceRegistryUtil;
21+
import org.junit.jupiter.api.Assertions;
2122
import org.junit.jupiter.api.Test;
2223

23-
import static org.hamcrest.Matchers.instanceOf;
24-
import static org.hamcrest.Matchers.startsWith;
25-
import static org.junit.Assert.assertThat;
26-
import static org.junit.Assert.fail;
24+
import static org.assertj.core.api.Assertions.assertThat;
25+
2726

2827
/**
2928
* Tests for scoping of generator names
@@ -48,11 +47,11 @@ public void testGlobalScoping() {
4847
// this will fail because both
4948
try {
5049
buildMetadata( true );
51-
fail();
50+
Assertions.fail();
5251
}
5352
catch (Exception e) {
54-
assertThat( e, instanceOf( IllegalArgumentException.class ) );
55-
assertThat( e.getMessage(), startsWith( "Duplicate generator name" ) );
53+
assertThat( e ).isInstanceOf( IllegalArgumentException.class );
54+
assertThat( e.getMessage() ).startsWith( "Duplicate generator name" );
5655
}
5756
}
5857

hibernate-core/src/test/java/org/hibernate/orm/test/idgen/biginteger/increment/BigIntegerIncrementGeneratorTest.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,20 @@
44
*/
55
package org.hibernate.orm.test.idgen.biginteger.increment;
66

7-
import java.math.BigInteger;
8-
9-
107
import org.hibernate.testing.orm.junit.DomainModel;
118
import org.hibernate.testing.orm.junit.SessionFactory;
129
import org.hibernate.testing.orm.junit.SessionFactoryScope;
1310
import org.junit.jupiter.api.AfterEach;
1411
import org.junit.jupiter.api.Test;
1512

16-
import static org.junit.Assert.assertEquals;
13+
import java.math.BigInteger;
14+
15+
import static org.junit.jupiter.api.Assertions.assertEquals;
1716

18-
@DomainModel(
19-
xmlMappings = "org/hibernate/orm/test/idgen/biginteger/increment/Mapping.hbm.xml"
20-
)
17+
@SuppressWarnings("JUnitMalformedDeclaration")
18+
@DomainModel(xmlMappings = "org/hibernate/orm/test/idgen/biginteger/increment/Mapping.hbm.xml")
2119
@SessionFactory
2220
public class BigIntegerIncrementGeneratorTest {
23-
2421
@Test
2522
public void testBasics(SessionFactoryScope scope) {
2623
scope.inTransaction(
@@ -40,6 +37,6 @@ public void testBasics(SessionFactoryScope scope) {
4037

4138
@AfterEach
4239
public void dropTestData(SessionFactoryScope scope) {
43-
scope.getSessionFactory().getSchemaManager().truncate();
40+
scope.dropData();
4441
}
4542
}

hibernate-core/src/test/java/org/hibernate/orm/test/idgen/biginteger/sequence/BigIntegerSequenceGeneratorTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
/**
1717
* @author Steve Ebersole
1818
*/
19-
@DomainModel(
20-
xmlMappings = "org/hibernate/orm/test/idgen/biginteger/sequence/Mapping.hbm.xml"
21-
)
19+
@SuppressWarnings("JUnitMalformedDeclaration")
20+
@DomainModel(xmlMappings = "org/hibernate/orm/test/idgen/biginteger/sequence/Mapping.hbm.xml")
2221
@SessionFactory
2322
@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsSequences.class )
2423
public class BigIntegerSequenceGeneratorTest {
@@ -46,6 +45,6 @@ public void testBasics(SessionFactoryScope scope) {
4645

4746
@AfterEach
4847
public void dropTestData(SessionFactoryScope scope) {
49-
scope.getSessionFactory().getSchemaManager().truncate();
48+
scope.dropData();
5049
}
5150
}

hibernate-core/src/test/java/org/hibernate/orm/test/idgen/biginteger/sequence/BigIntegerSequenceGeneratorZeroScaleTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@
2020
*
2121
* @author Gail Badner
2222
*/
23-
@DomainModel(
24-
xmlMappings = "org/hibernate/orm/test/idgen/biginteger/sequence/ZeroScaleMapping.hbm.xml"
25-
)
23+
@SuppressWarnings("JUnitMalformedDeclaration")
24+
@DomainModel(xmlMappings = "org/hibernate/orm/test/idgen/biginteger/sequence/ZeroScaleMapping.hbm.xml")
2625
@SessionFactory
2726
@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsSequences.class )
2827
public class BigIntegerSequenceGeneratorZeroScaleTest extends BigIntegerSequenceGeneratorTest {
@@ -31,5 +30,4 @@ public class BigIntegerSequenceGeneratorZeroScaleTest extends BigIntegerSequence
3130
public void testBasics(SessionFactoryScope scope) {
3231
super.testBasics( scope );
3332
}
34-
3533
}

0 commit comments

Comments
 (0)