Skip to content

Commit 3977260

Browse files
committed
HHH-19846 - Remove JUnit4: org.hibernate.orm.test.annotations
Signed-off-by: Jan Schatteman <[email protected]>
1 parent 03caeea commit 3977260

File tree

9 files changed

+127
-146
lines changed

9 files changed

+127
-146
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/CreationTimestampTest.java

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import org.hibernate.Session;
88
import org.hibernate.StatelessSession;
99
import org.hibernate.annotations.CreationTimestamp;
10-
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
11-
import org.junit.Assert;
12-
import org.junit.Test;
10+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
11+
import org.hibernate.testing.orm.junit.Jpa;
12+
import org.junit.jupiter.api.Test;
1313

1414
import jakarta.persistence.Column;
1515
import jakarta.persistence.Entity;
@@ -23,22 +23,16 @@
2323

2424
import org.hibernate.testing.orm.junit.JiraKey;
2525

26-
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
26+
import static org.junit.jupiter.api.Assertions.assertNotNull;
2727

2828
/**
2929
* @author Borys Piela
3030
*/
31-
public class CreationTimestampTest extends BaseEntityManagerFunctionalTestCase {
32-
33-
@Override
34-
protected Class<?>[] getAnnotatedClasses() {
35-
return new Class<?>[]{
36-
Event.class
37-
};
38-
}
31+
@Jpa(annotatedClasses = {CreationTimestampTest.Event.class})
32+
public class CreationTimestampTest {
3933

4034
@Entity(name = "Event")
41-
private static class Event {
35+
static class Event {
4236

4337
@Id
4438
@GeneratedValue
@@ -173,8 +167,8 @@ public ZonedDateTime getZonedDateTime() {
173167
}
174168

175169
@Test
176-
public void generatesCurrentTimestamp() {
177-
doInJPA(this::entityManagerFactory, entityManager -> {
170+
public void generatesCurrentTimestamp(EntityManagerFactoryScope scope) {
171+
scope.inTransaction( entityManager -> {
178172
Event event = new Event();
179173
entityManager.persist(event);
180174
entityManager.flush();
@@ -184,8 +178,8 @@ public void generatesCurrentTimestamp() {
184178

185179
@Test
186180
@JiraKey( value = "HHH-16240")
187-
public void generatesCurrentTimestampInStatelessSession() {
188-
doInJPA(this::entityManagerFactory, entityManager -> {
181+
public void generatesCurrentTimestampInStatelessSession(EntityManagerFactoryScope scope) {
182+
scope.inTransaction( entityManager -> {
189183
Session session = entityManager.unwrap( Session.class);
190184
try (StatelessSession statelessSession = session.getSessionFactory().openStatelessSession()) {
191185
Event event = new Event();
@@ -198,20 +192,20 @@ public void generatesCurrentTimestampInStatelessSession() {
198192
}
199193

200194
private void check(Event event) {
201-
Assert.assertNotNull(event.getDate());
202-
Assert.assertNotNull(event.getCalendar());
203-
Assert.assertNotNull(event.getSqlDate());
204-
Assert.assertNotNull(event.getTime());
205-
Assert.assertNotNull(event.getTimestamp());
206-
Assert.assertNotNull(event.getInstant());
207-
Assert.assertNotNull(event.getLocalDate());
208-
Assert.assertNotNull(event.getLocalDateTime());
209-
Assert.assertNotNull(event.getLocalTime());
210-
Assert.assertNotNull(event.getMonthDay());
211-
Assert.assertNotNull(event.getOffsetDateTime());
212-
Assert.assertNotNull(event.getOffsetTime());
213-
Assert.assertNotNull(event.getYear());
214-
Assert.assertNotNull(event.getYearMonth());
215-
Assert.assertNotNull(event.getZonedDateTime());
195+
assertNotNull(event.getDate());
196+
assertNotNull(event.getCalendar());
197+
assertNotNull(event.getSqlDate());
198+
assertNotNull(event.getTime());
199+
assertNotNull(event.getTimestamp());
200+
assertNotNull(event.getInstant());
201+
assertNotNull(event.getLocalDate());
202+
assertNotNull(event.getLocalDateTime());
203+
assertNotNull(event.getLocalTime());
204+
assertNotNull(event.getMonthDay());
205+
assertNotNull(event.getOffsetDateTime());
206+
assertNotNull(event.getOffsetTime());
207+
assertNotNull(event.getYear());
208+
assertNotNull(event.getYearMonth());
209+
assertNotNull(event.getZonedDateTime());
216210
}
217211
}

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/GenericConverterAutoApplyTest.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
import jakarta.persistence.AttributeConverter;
88
import jakarta.persistence.Converter;
99
import jakarta.persistence.Entity;
10+
import jakarta.persistence.EntityManager;
1011
import jakarta.persistence.GeneratedValue;
1112
import jakarta.persistence.Id;
1213
import jakarta.persistence.metamodel.EntityType;
1314
import jakarta.persistence.metamodel.SingularAttribute;
14-
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
15+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
1516
import org.hibernate.testing.orm.junit.JiraKey;
17+
import org.hibernate.testing.orm.junit.Jpa;
1618
import org.hibernate.type.BasicType;
17-
import org.junit.Test;
19+
import org.junit.jupiter.api.Test;
1820

1921
import java.util.List;
2022

@@ -24,25 +26,25 @@
2426
* @author Yanming Zhou
2527
*/
2628
@JiraKey("HHH-18012")
27-
public class GenericConverterAutoApplyTest extends BaseEntityManagerFunctionalTestCase {
28-
29-
@Override
30-
protected Class<?>[] getAnnotatedClasses() {
31-
return new Class[]{IntegerArrayConverter.class, IntegerListConverter.class, TestEntity.class};
32-
}
29+
@Jpa(annotatedClasses = {
30+
GenericConverterAutoApplyTest.IntegerArrayConverter.class,
31+
GenericConverterAutoApplyTest.IntegerListConverter.class,
32+
GenericConverterAutoApplyTest.TestEntity.class}
33+
)
34+
public class GenericConverterAutoApplyTest {
3335

3436
@Test
35-
public void genericArrayIsAutoApplied() {
36-
assertAttributeIsMappingToString("integerArray");
37+
public void genericArrayIsAutoApplied(EntityManagerFactoryScope scope) {
38+
assertAttributeIsMappingToString( scope.getEntityManagerFactory().createEntityManager(), "integerArray" );
3739
}
3840

3941
@Test
40-
public void genericListIsAutoApplied() {
41-
assertAttributeIsMappingToString("integerList");
42+
public void genericListIsAutoApplied(EntityManagerFactoryScope scope) {
43+
assertAttributeIsMappingToString( scope.getEntityManagerFactory().createEntityManager(), "integerList" );
4244
}
4345

44-
private void assertAttributeIsMappingToString(String name) {
45-
EntityType<?> entityType = getOrCreateEntityManager().getMetamodel().entity(TestEntity.class);
46+
private void assertAttributeIsMappingToString(EntityManager em, String name) {
47+
EntityType<?> entityType = em.getMetamodel().entity(TestEntity.class);
4648
assertThat(entityType.getAttribute(name)).isInstanceOfSatisfying(SingularAttribute.class,
4749
sa -> assertThat(sa.getType()).isInstanceOfSatisfying(BasicType.class,
4850
bt -> assertThat(bt.getJdbcJavaType().getJavaType()).isEqualTo(String.class)

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/HHH16122Test.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,17 @@
99
import jakarta.persistence.Entity;
1010
import jakarta.persistence.Id;
1111
import jakarta.persistence.MappedSuperclass;
12-
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
12+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
1313
import org.hibernate.testing.orm.junit.JiraKey;
14-
import org.junit.Test;
14+
import org.hibernate.testing.orm.junit.Jpa;
15+
import org.junit.jupiter.api.Test;
1516

1617
@JiraKey( value = "HHH-16122" )
17-
public class HHH16122Test extends BaseEntityManagerFunctionalTestCase {
18-
@Override
19-
protected Class<?>[] getAnnotatedClasses() {
20-
return new Class[] { ValueConverter.class, SuperClass.class, SubClass.class };
21-
}
18+
@Jpa( annotatedClasses = {HHH16122Test.ValueConverter.class, HHH16122Test.SuperClass.class, HHH16122Test.SubClass.class} )
19+
public class HHH16122Test {
2220

2321
@Test
24-
public void testGenericSuperClassWithConverter() {
22+
public void testGenericSuperClassWithConverter(EntityManagerFactoryScope scope) {
2523
// The test is successful if the entity manager factory can be built.
2624
}
2725

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/InMemoryCreationTimestampNullableColumnTest.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,19 @@
1212

1313
import org.hibernate.annotations.CreationTimestamp;
1414
import org.hibernate.annotations.NaturalId;
15-
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
1615

16+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
1717
import org.hibernate.testing.orm.junit.JiraKey;
18-
import org.junit.Assert;
19-
import org.junit.Test;
20-
21-
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
18+
import org.hibernate.testing.orm.junit.Jpa;
19+
import org.junit.jupiter.api.Assertions;
20+
import org.junit.jupiter.api.Test;
2221

2322
/**
2423
* @author Vlad Mihalcea
2524
*/
2625
@JiraKey(value = "HHH-11096")
27-
public class InMemoryCreationTimestampNullableColumnTest extends BaseEntityManagerFunctionalTestCase {
28-
29-
@Override
30-
protected Class<?>[] getAnnotatedClasses() {
31-
return new Class<?>[] {
32-
Person.class
33-
};
34-
}
26+
@Jpa( annotatedClasses = {InMemoryCreationTimestampNullableColumnTest.Person.class} )
27+
public class InMemoryCreationTimestampNullableColumnTest {
3528

3629
@Entity(name = "Person")
3730
public static class Person {
@@ -65,14 +58,14 @@ public void setCreationDate(Date creationDate) {
6558
}
6659

6760
@Test
68-
public void generatesCurrentTimestamp() {
69-
doInJPA( this::entityManagerFactory, entityManager -> {
61+
public void generatesCurrentTimestamp(EntityManagerFactoryScope scope) {
62+
scope.inTransaction( entityManager -> {
7063
Person person = new Person();
7164
person.setName( "John Doe" );
7265
entityManager.persist( person );
7366

7467
entityManager.flush();
75-
Assert.assertNotNull( person.getCreationDate() );
68+
Assertions.assertNotNull( person.getCreationDate() );
7669
} );
7770
}
7871
}

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/JoinedSubclassTest.java

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,46 @@
77
import jakarta.persistence.criteria.CriteriaBuilder;
88
import jakarta.persistence.criteria.CriteriaQuery;
99

10-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
1110
import org.hibernate.orm.test.annotations.inheritance.Carrot;
1211
import org.hibernate.orm.test.annotations.inheritance.Tomato;
1312
import org.hibernate.orm.test.annotations.inheritance.Vegetable;
1413
import org.hibernate.orm.test.annotations.inheritance.VegetablePk;
1514

16-
import org.junit.Test;
15+
import org.hibernate.testing.orm.junit.DomainModel;
16+
import org.hibernate.testing.orm.junit.SessionFactory;
17+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
18+
import org.junit.jupiter.api.Test;
1719

18-
import static org.junit.Assert.assertEquals;
19-
import static org.junit.Assert.assertNotNull;
20-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
22+
import static org.junit.jupiter.api.Assertions.assertNotNull;
2123

2224
/**
2325
* @author Emmanuel Bernard
2426
*/
25-
public class JoinedSubclassTest extends BaseCoreFunctionalTestCase {
27+
@DomainModel(annotatedClasses = {
28+
Boat.class,
29+
Ferry.class,
30+
AmericaCupClass.class,
31+
Country.class,
32+
Vegetable.class,
33+
Carrot.class,
34+
Tomato.class
35+
})
36+
@SessionFactory
37+
public class JoinedSubclassTest {
2638
@Test
27-
public void testDefaultValues() {
39+
public void testDefaultValues(SessionFactoryScope scope) {
2840
Ferry ferry = new Ferry();
29-
inTransaction(
41+
scope.inTransaction(
3042
s -> {
3143
ferry.setSize( 2 );
3244
ferry.setSea( "Channel" );
3345
s.persist( ferry );
3446
}
3547
);
3648

37-
inTransaction(
49+
scope.inTransaction(
3850
s -> {
3951
Ferry f = s.get( Ferry.class, ferry.getId() );
4052
assertNotNull( f );
@@ -46,10 +58,10 @@ public void testDefaultValues() {
4658
}
4759

4860
@Test
49-
public void testDeclaredValues() {
61+
public void testDeclaredValues(SessionFactoryScope scope) {
5062
Country country = new Country();
5163
AmericaCupClass americaCupClass = new AmericaCupClass();
52-
inTransaction(
64+
scope.inTransaction(
5365
s -> {
5466
country.setName( "France" );
5567
americaCupClass.setSize( 2 );
@@ -59,7 +71,7 @@ public void testDeclaredValues() {
5971
}
6072
);
6173

62-
inTransaction(
74+
scope.inTransaction(
6375
s -> {
6476
AmericaCupClass f = s.get( AmericaCupClass.class, americaCupClass.getId() );
6577
assertNotNull( f );
@@ -72,8 +84,8 @@ public void testDeclaredValues() {
7284
}
7385

7486
@Test
75-
public void testCompositePk() {
76-
inTransaction(
87+
public void testCompositePk(SessionFactoryScope scope) {
88+
scope.inTransaction(
7789
s -> {
7890
Carrot c = new Carrot();
7991
VegetablePk pk = new VegetablePk();
@@ -85,30 +97,17 @@ public void testCompositePk() {
8597
}
8698
);
8799

88-
inTransaction(
100+
scope.inTransaction(
89101
s -> {
90102
CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder();
91103
CriteriaQuery<Vegetable> criteria = criteriaBuilder.createQuery( Vegetable.class );
92104
criteria.from( Vegetable.class );
93105
Vegetable v = s.createQuery( criteria ).uniqueResult();
94-
// Vegetable v = (Vegetable) s.createCriteria( Vegetable.class ).uniqueResult();
95-
assertTrue( v instanceof Carrot );
106+
assertInstanceOf( Carrot.class, v );
96107
Carrot result = (Carrot) v;
97108
assertEquals( 23, result.getLength() );
98109
}
99110
);
100111
}
101112

102-
@Override
103-
protected Class[] getAnnotatedClasses() {
104-
return new Class[] {
105-
Boat.class,
106-
Ferry.class,
107-
AmericaCupClass.class,
108-
Country.class,
109-
Vegetable.class,
110-
Carrot.class,
111-
Tomato.class
112-
};
113-
}
114113
}

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/SafeMappingTest.java

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

7-
import org.junit.Test;
7+
import org.junit.jupiter.api.Test;
88

99
import org.hibernate.AnnotationException;
1010
import org.hibernate.SessionFactory;
@@ -14,7 +14,7 @@
1414
import org.hibernate.service.ServiceRegistry;
1515
import org.hibernate.testing.ServiceRegistryBuilder;
1616

17-
import static org.junit.Assert.fail;
17+
import static org.junit.jupiter.api.Assertions.fail;
1818

1919
/**
2020
* @author Emmanuel Bernard

0 commit comments

Comments
 (0)