Skip to content

Commit ff52b41

Browse files
committed
HHH-19846 - Drop JUnit 4 usage
Not converted... * 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 * org.hibernate.orm.test.type.AbstractJavaTimeTypeTest subtypes - crazy parameterization (see org.hibernate.orm.test.tm.InterceptorTransactionTest)
1 parent d21acdd commit ff52b41

File tree

4 files changed

+122
-174
lines changed

4 files changed

+122
-174
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/cdi/converters/delayed/DelayedCdiHostedConverterTest.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,32 @@
66

77
import jakarta.enterprise.inject.se.SeContainer;
88
import jakarta.enterprise.inject.se.SeContainerInitializer;
9-
109
import org.hibernate.boot.MetadataSources;
1110
import org.hibernate.boot.registry.BootstrapServiceRegistry;
1211
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
1312
import org.hibernate.boot.registry.StandardServiceRegistry;
1413
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
1514
import org.hibernate.cfg.AvailableSettings;
1615
import org.hibernate.engine.spi.SessionFactoryImplementor;
17-
import org.hibernate.tool.schema.Action;
18-
19-
import org.hibernate.testing.junit4.BaseUnitTestCase;
20-
import org.hibernate.testing.util.ServiceRegistryUtil;
21-
2216
import org.hibernate.orm.test.cdi.converters.ConverterBean;
2317
import org.hibernate.orm.test.cdi.converters.MonitorBean;
2418
import org.hibernate.orm.test.cdi.converters.TheEntity;
25-
import org.junit.Test;
19+
import org.hibernate.testing.orm.junit.BaseUnitTest;
20+
import org.hibernate.testing.util.ServiceRegistryUtil;
21+
import org.hibernate.tool.schema.Action;
22+
import org.junit.jupiter.api.Test;
2623

2724
import static org.hibernate.testing.transaction.TransactionUtil2.inTransaction;
28-
import static org.junit.Assert.assertEquals;
29-
import static org.junit.Assert.assertFalse;
30-
import static org.junit.Assert.assertNotNull;
31-
import static org.junit.Assert.assertTrue;
25+
import static org.junit.jupiter.api.Assertions.assertEquals;
26+
import static org.junit.jupiter.api.Assertions.assertFalse;
27+
import static org.junit.jupiter.api.Assertions.assertNotNull;
28+
import static org.junit.jupiter.api.Assertions.assertTrue;
3229

3330
/**
3431
* @author Steve Ebersole
3532
*/
36-
public class DelayedCdiHostedConverterTest extends BaseUnitTestCase {
33+
@BaseUnitTest
34+
public class DelayedCdiHostedConverterTest {
3735
@Test
3836
public void testIt() {
3937
MonitorBean.reset();

hibernate-core/src/test/java/org/hibernate/orm/test/cdi/converters/legacy/ConversionAutoApplyTest.java

Lines changed: 29 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,137 +4,113 @@
44
*/
55
package org.hibernate.orm.test.cdi.converters.legacy;
66

7-
import static org.junit.Assert.assertEquals;
8-
9-
import java.math.BigDecimal;
10-
import java.math.RoundingMode;
11-
127
import jakarta.persistence.AttributeConverter;
138
import jakarta.persistence.Column;
149
import jakarta.persistence.Converter;
1510
import jakarta.persistence.Entity;
16-
import jakarta.persistence.EntityManager;
1711
import jakarta.persistence.Id;
1812
import jakarta.persistence.Table;
19-
20-
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
13+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
2114
import org.hibernate.testing.orm.junit.JiraKey;
22-
import org.junit.Test;
15+
import org.hibernate.testing.orm.junit.Jpa;
16+
import org.junit.jupiter.api.Test;
17+
18+
import java.math.BigDecimal;
19+
import java.math.RoundingMode;
20+
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
2322

2423
/**
2524
* Test AttributeConverter functioning in case where entity type is derived from jdbc type.
2625
*
2726
* @author Karthik Abram
2827
*/
28+
@SuppressWarnings("JUnitMalformedDeclaration")
2929
@JiraKey( value = "HHH-10549" )
30-
public class ConversionAutoApplyTest extends BaseEntityManagerFunctionalTestCase {
31-
30+
@Jpa(annotatedClasses = {
31+
ConversionAutoApplyTest.Widget.class,
32+
ConversionAutoApplyTest.MoneyConverter.class
33+
})
34+
public class ConversionAutoApplyTest {
3235
@Test
33-
public void testConverterIsNotIncorrectlyApplied() {
34-
Widget w = new Widget();
35-
w.setId( 1 );
36-
w.setDimension( new BigDecimal( "1.0" ) );
37-
w.setCost( new Money( "2.0" ) );
38-
39-
EntityManager em = entityManagerFactory().createEntityManager();
40-
em.getTransaction().begin();
41-
em.persist( w );
42-
em.getTransaction().commit();
43-
em.close();
44-
45-
em = entityManagerFactory().createEntityManager();
46-
em.getTransaction().begin();
47-
Widget recorded = em.find( Widget.class, 1 );
48-
assertEquals( 1, recorded.getId() );
49-
50-
em.remove(recorded);
51-
em.getTransaction().commit();
52-
em.close();
36+
public void testConverterIsNotIncorrectlyApplied(EntityManagerFactoryScope factoryScope) {
37+
factoryScope.inTransaction( (em) -> {
38+
Widget w = new Widget();
39+
w.setId( 1 );
40+
w.setDimension( new BigDecimal( "1.0" ) );
41+
w.setCost( new Money( "2.0" ) );
42+
em.persist( w );
43+
} );
44+
45+
factoryScope.inTransaction( (em) -> {
46+
Widget recorded = em.find( Widget.class, 1 );
47+
assertEquals( 1, recorded.getId() );
48+
49+
em.remove(recorded);
50+
} );
5351
}
5452

55-
56-
@Override
57-
protected Class<?>[] getAnnotatedClasses() {
58-
return new Class[] { Widget.class, MoneyConverter.class };
59-
}
60-
61-
6253
public static class Money extends BigDecimal {
63-
6454
public Money(String value) {
6555
super( value );
6656
}
6757

68-
6958
public Money(BigDecimal value) {
7059
super( value.toString() );
7160
}
7261

73-
7462
@Override
7563
public BigDecimal add(BigDecimal augend) {
7664
return new Money( this.add( augend ).setScale( 10, RoundingMode.HALF_EVEN ) );
7765
}
7866
}
7967

80-
8168
@Converter( autoApply = true )
8269
public static class MoneyConverter implements AttributeConverter<Money, BigDecimal> {
83-
8470
@Override
8571
public BigDecimal convertToDatabaseColumn(Money attribute) {
8672
return attribute == null ? null : new BigDecimal(attribute.toString());
8773
}
8874

89-
9075
@Override
9176
public Money convertToEntityAttribute(BigDecimal dbData) {
9277
return dbData == null ? null : new Money( dbData.toString() );
9378
}
94-
9579
}
9680

9781

9882
@Entity
9983
@Table( name = "Widget" )
10084
public static class Widget {
101-
10285
private int id;
10386
private BigDecimal dimension;
10487
private Money cost;
10588

106-
10789
@Id
10890
public int getId() {
10991
return id;
11092
}
11193

112-
11394
public void setId(int id) {
11495
this.id = id;
11596
}
11697

117-
11898
public BigDecimal getDimension() {
11999
return dimension;
120100
}
121101

122-
123102
public void setDimension(BigDecimal dimension) {
124103
this.dimension = dimension;
125104
}
126105

127-
128106
@Column( name = "cost" )
129107
public Money getCost() {
130108
return cost;
131109
}
132110

133-
134111
public void setCost(Money cost) {
135112
this.cost = cost;
136113
}
137-
138114
}
139115

140116

0 commit comments

Comments
 (0)