Skip to content

Commit 6e1047f

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

10 files changed

+137
-164
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/InMemoryTimestampGenerationBatchTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.hibernate.testing.orm.junit.SessionFactoryScope;
2020
import org.hibernate.testing.orm.junit.Setting;
2121
import org.hibernate.testing.orm.junit.SettingProvider;
22+
import org.junit.jupiter.api.BeforeEach;
2223
import org.junit.jupiter.api.Test;
2324

2425
import java.time.Instant;
@@ -34,13 +35,19 @@
3435
@SessionFactory(generateStatistics = true)
3536
@ServiceRegistry(settings = @Setting(name = AvailableSettings.STATEMENT_BATCH_SIZE, value = "5"),
3637
settingProviders = @SettingProvider(settingName = CurrentTimestampGeneration.CLOCK_SETTING_NAME,
37-
provider = InMemoryTimestampGenerationBatchTest.MutableClockProvider.class))
38+
provider = MutableClockSettingProvider.class))
3839
@Jira("https://hibernate.atlassian.net/browse/HHH-19840")
3940
public class InMemoryTimestampGenerationBatchTest {
40-
private static final MutableClock clock = new MutableClock();
41+
private MutableClock clock;
4142

4243
private static final int PERSON_COUNT = 8;
4344

45+
@BeforeEach
46+
public void setup(SessionFactoryScope scope) {
47+
clock = CurrentTimestampGeneration.getClock( scope.getSessionFactory() );
48+
clock.reset();
49+
}
50+
4451
@Test
4552
public void test(SessionFactoryScope scope) throws InterruptedException {
4653
final var statistics = scope.getSessionFactory().getStatistics();
@@ -94,13 +101,6 @@ public void test(SessionFactoryScope scope) throws InterruptedException {
94101
} );
95102
}
96103

97-
public static class MutableClockProvider implements SettingProvider.Provider<Object> {
98-
@Override
99-
public Object getSetting() {
100-
return clock;
101-
}
102-
}
103-
104104
@Entity(name = "Person")
105105
public static class Person {
106106
@Id

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import jakarta.persistence.Column;
88
import jakarta.persistence.Entity;
99
import jakarta.persistence.Id;
10+
import org.hibernate.SessionFactory;
1011
import org.hibernate.annotations.CreationTimestamp;
1112
import org.hibernate.annotations.SourceType;
1213
import org.hibernate.annotations.UpdateTimestamp;
@@ -15,6 +16,7 @@
1516
import org.hibernate.testing.orm.junit.Jira;
1617
import org.hibernate.testing.orm.junit.Jpa;
1718
import org.hibernate.testing.orm.junit.SettingProvider;
19+
import org.junit.jupiter.api.BeforeEach;
1820
import org.junit.jupiter.api.Test;
1921

2022
import java.time.Instant;
@@ -26,10 +28,16 @@
2628

2729
@Jpa(annotatedClasses = InMemoryTimestampGenerationTest.Person.class,
2830
settingProviders = @SettingProvider(settingName = CurrentTimestampGeneration.CLOCK_SETTING_NAME,
29-
provider = InMemoryTimestampGenerationTest.MutableClockProvider.class))
31+
provider = MutableClockSettingProvider.class))
3032
@Jira("https://hibernate.atlassian.net/browse/HHH-19840")
3133
public class InMemoryTimestampGenerationTest {
32-
private static final MutableClock clock = new MutableClock();
34+
private MutableClock clock;
35+
36+
@BeforeEach
37+
public void setup(EntityManagerFactoryScope scope) {
38+
clock = CurrentTimestampGeneration.getClock( scope.getEntityManagerFactory().unwrap( SessionFactory.class ) );
39+
clock.reset();
40+
}
3341

3442
@Test
3543
public void test(EntityManagerFactoryScope scope) throws InterruptedException {
@@ -63,13 +71,6 @@ public void test(EntityManagerFactoryScope scope) throws InterruptedException {
6371
} );
6472
}
6573

66-
static class MutableClockProvider implements SettingProvider.Provider<Object> {
67-
@Override
68-
public Object getSetting() {
69-
return clock;
70-
}
71-
}
72-
7374
@Entity(name = "Person")
7475
static class Person {
7576
@Id

0 commit comments

Comments
 (0)