Skip to content

Commit 1e4516c

Browse files
committed
HHH-19846 - Remove JUnit4: org.hibernate.orm.test.dialect
Signed-off-by: Jan Schatteman <[email protected]>
1 parent 0a347e1 commit 1e4516c

File tree

6 files changed

+57
-65
lines changed

6 files changed

+57
-65
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/dialect/DB2390DialectTestCase.java

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,43 @@
1212
import jakarta.persistence.Id;
1313

1414
import org.hibernate.dialect.DB2zDialect;
15-
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
16-
import org.junit.After;
17-
import org.junit.Before;
18-
import org.junit.Test;
15+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
16+
import org.hibernate.testing.orm.junit.Jpa;
17+
import org.junit.jupiter.api.AfterAll;
18+
import org.junit.jupiter.api.BeforeAll;
19+
import org.junit.jupiter.api.Test;
1920

20-
import org.hibernate.testing.RequiresDialect;
21+
import org.hibernate.testing.orm.junit.RequiresDialect;
2122
import org.hibernate.testing.orm.junit.JiraKey;
2223

23-
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
24-
import static org.junit.Assert.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertEquals;
2525

2626
/**
2727
* @author Chris Cranford
2828
*/
2929
@JiraKey(value = "HHH-11747")
3030
@RequiresDialect(DB2zDialect.class)
31-
public class DB2390DialectTestCase extends BaseEntityManagerFunctionalTestCase {
32-
@Override
33-
protected Class<?>[] getAnnotatedClasses() {
34-
return new Class<?>[] { SimpleEntity.class };
31+
@Jpa(annotatedClasses = {DB2390DialectTestCase.SimpleEntity.class})
32+
public class DB2390DialectTestCase {
33+
34+
@BeforeAll
35+
public void populateSchema(EntityManagerFactoryScope scope) {
36+
scope.inTransaction( entityManager -> {
37+
for ( int i = 0; i < 10; ++i ) {
38+
final SimpleEntity simpleEntity = new SimpleEntity( i, "Entity" + i );
39+
entityManager.persist( simpleEntity );
40+
}
41+
} );
42+
}
43+
44+
@AfterAll
45+
public void cleanSchema(EntityManagerFactoryScope scope) {
46+
scope.inTransaction( entityManager -> scope.getEntityManagerFactory().getSchemaManager().truncate() );
3547
}
3648

3749
@Test
38-
public void testLegacyLimitHandlerWithNoOffset() {
39-
doInJPA( this::entityManagerFactory, entityManager -> {
50+
public void testLegacyLimitHandlerWithNoOffset(EntityManagerFactoryScope scope) {
51+
scope.inTransaction( entityManager -> {
4052
List<SimpleEntity> results = entityManager.createQuery( "FROM SimpleEntity", SimpleEntity.class )
4153
.setMaxResults( 2 )
4254
.getResultList();
@@ -45,8 +57,8 @@ public void testLegacyLimitHandlerWithNoOffset() {
4557
}
4658

4759
@Test
48-
public void testLegacyLimitHandlerWithOffset() {
49-
doInJPA( this::entityManagerFactory, entityManager -> {
60+
public void testLegacyLimitHandlerWithOffset(EntityManagerFactoryScope scope) {
61+
scope.inTransaction( entityManager -> {
5062
List<SimpleEntity> results = entityManager.createQuery( "FROM SimpleEntity", SimpleEntity.class )
5163
.setFirstResult( 2 )
5264
.setMaxResults( 2 )
@@ -55,23 +67,6 @@ public void testLegacyLimitHandlerWithOffset() {
5567
} );
5668
}
5769

58-
@Before
59-
public void populateSchema() {
60-
doInJPA( this::entityManagerFactory, entityManager -> {
61-
for ( int i = 0; i < 10; ++i ) {
62-
final SimpleEntity simpleEntity = new SimpleEntity( i, "Entity" + i );
63-
entityManager.persist( simpleEntity );
64-
}
65-
} );
66-
}
67-
68-
@After
69-
public void cleanSchema() {
70-
doInJPA( this::entityManagerFactory, entityManager -> {
71-
entityManager.createQuery( "DELETE FROM SimpleEntity" ).executeUpdate();
72-
} );
73-
}
74-
7570
@Entity(name = "SimpleEntity")
7671
public static class SimpleEntity {
7772
@Id

hibernate-core/src/test/java/org/hibernate/orm/test/dialect/DB2DialectTestCase.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
import org.hibernate.testing.orm.junit.RequiresDialect;
1313
import org.hibernate.type.spi.TypeConfiguration;
1414

15-
import org.junit.Before;
16-
import org.junit.Test;
15+
import org.junit.jupiter.api.BeforeEach;
16+
import org.junit.jupiter.api.Test;
1717

1818
import org.hibernate.testing.orm.junit.JiraKey;
19-
import org.hibernate.testing.junit4.BaseUnitTestCase;
2019

21-
import static org.junit.Assert.assertEquals;
22-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
2322

2423
/**
2524
* DB2 dialect related test cases
@@ -28,11 +27,11 @@
2827
*/
2928

3029
@RequiresDialect(DB2Dialect.class)
31-
public class DB2DialectTestCase extends BaseUnitTestCase {
30+
public class DB2DialectTestCase {
3231
private final DB2Dialect dialect = new DB2Dialect();
3332
private TypeConfiguration typeConfiguration;
3433

35-
@Before
34+
@BeforeEach
3635
public void setup() {
3736
typeConfiguration = new TypeConfiguration();
3837
dialect.contributeTypes( () -> typeConfiguration, null );
@@ -53,23 +52,23 @@ public void testGetDefaultBinaryTypeName() {
5352
@JiraKey(value = "HHH-6866")
5453
public void testGetExplicitBinaryTypeName() {
5554
// lower bound
56-
String actual = typeConfiguration.getDdlTypeRegistry().getTypeName( Types.BINARY, Size.length( 1) );
55+
String actual = typeConfiguration.getDdlTypeRegistry().getTypeName( Types.BINARY, Size.length(1) );
5756
assertEquals(
5857
"Wrong binary type",
5958
"binary(1)",
6059
actual
6160
);
6261

6362
// upper bound
64-
actual = typeConfiguration.getDdlTypeRegistry().getTypeName( Types.BINARY, Size.length( 254) );
63+
actual = typeConfiguration.getDdlTypeRegistry().getTypeName( Types.BINARY, Size.length(254) );
6564
assertEquals(
6665
"Wrong binary type. 254 is the max length in DB2",
6766
"binary(254)",
6867
actual
6968
);
7069

7170
// exceeding upper bound
72-
actual = typeConfiguration.getDdlTypeRegistry().getTypeName( Types.BINARY, Size.length( 255) );
71+
actual = typeConfiguration.getDdlTypeRegistry().getTypeName( Types.BINARY, Size.length(255) );
7372
assertEquals(
7473
"Wrong binary type. Should be varchar for length > 254",
7574
"varbinary(255)",
@@ -85,8 +84,8 @@ public void testIntegerOverflowForMaxResults() {
8584
rowSelection.setMaxRows(Integer.MAX_VALUE);
8685
String sql = dialect.getLimitHandler().processSql( "select a.id from tbl_a a order by a.id", -1, null, new LimitQueryOptions( rowSelection ) );
8786
assertTrue(
88-
"Integer overflow for max rows in: " + sql,
89-
sql.contains("fetch next ? rows only")
90-
);
87+
sql.contains("fetch next ? rows only"),
88+
"Integer overflow for max rows in: " + sql
89+
);
9190
}
9291
}

hibernate-core/src/test/java/org/hibernate/orm/test/dialect/Db2VariantDialectInitTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import org.hibernate.dialect.DB2zDialect;
99
import org.hibernate.testing.orm.junit.JiraKey;
1010
import org.hibernate.testing.orm.junit.RequiresDialect;
11-
import org.junit.Test;
11+
import org.junit.jupiter.api.Test;
1212

13-
import static org.junit.Assert.assertNotNull;
13+
import static org.junit.jupiter.api.Assertions.assertNotNull;
1414

1515
/**
1616
* @author Steve Ebersole

hibernate-core/src/test/java/org/hibernate/orm/test/dialect/DialectMinimumVersionTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import org.junit.jupiter.api.Test;
1616
import org.junit.jupiter.api.extension.RegisterExtension;
1717

18-
19-
2018
import static org.hibernate.internal.CoreMessageLogger.CORE_LOGGER;
2119

2220
/**

hibernate-core/src/test/java/org/hibernate/orm/test/dialect/HANADialectTestCase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
import java.util.Map;
2727

2828
import static org.assertj.core.api.Assertions.assertThat;
29-
import static org.junit.Assert.assertEquals;
30-
import static org.junit.Assert.fail;
29+
import static org.junit.jupiter.api.Assertions.assertEquals;
30+
import static org.junit.jupiter.api.Assertions.fail;
3131

3232
@SuppressWarnings("JUnitMalformedDeclaration")
3333
@ServiceRegistry

hibernate-core/src/test/java/org/hibernate/orm/test/dialect/PostgreSQLDialectTestCase.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,26 @@
3131
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
3232
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
3333
import org.hibernate.testing.orm.junit.JiraKey;
34-
import org.hibernate.testing.junit4.BaseUnitTestCase;
3534
import org.hibernate.testing.orm.junit.RequiresDialect;
3635
import org.hibernate.type.spi.TypeConfiguration;
37-
import org.junit.Test;
36+
import org.junit.jupiter.api.Test;
3837

3938
import org.mockito.Mockito;
4039

4140
import static org.hamcrest.core.Is.is;
42-
import static org.junit.Assert.assertNotNull;
43-
import static org.junit.Assert.assertThat;
44-
import static org.junit.Assert.assertTrue;
45-
import static org.junit.Assert.assertEquals;
46-
import static org.junit.Assert.fail;
41+
import static org.hamcrest.MatcherAssert.assertThat;
42+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
43+
import static org.junit.jupiter.api.Assertions.assertNotNull;
44+
import static org.junit.jupiter.api.Assertions.assertEquals;
45+
import static org.junit.jupiter.api.Assertions.fail;
4746

4847
/**
4948
* Test case for PostgreSQL specific things.
5049
* @author Bryan Varner
5150
* @author Christoph Dreis
5251
*/
5352
@RequiresDialect(PostgreSQLDialect.class)
54-
public class PostgreSQLDialectTestCase extends BaseUnitTestCase {
53+
public class PostgreSQLDialectTestCase {
5554

5655
@Test
5756
@JiraKey( value = "HHH-7251")
@@ -61,7 +60,7 @@ public void testDeadlockException() {
6160
assertNotNull(delegate);
6261

6362
JDBCException exception = delegate.convert(new SQLException("Deadlock Detected", "40P01"), "", "");
64-
assertTrue(exception instanceof LockAcquisitionException);
63+
assertInstanceOf( LockAcquisitionException.class, exception );
6564
}
6665

6766
@Test
@@ -72,7 +71,7 @@ public void testTimeoutException() {
7271
assertNotNull(delegate);
7372

7473
JDBCException exception = delegate.convert(new SQLException("Lock Not Available", "55P03"), "", "");
75-
assertTrue(exception instanceof PessimisticLockException);
74+
assertInstanceOf( PessimisticLockException.class, exception );
7675
}
7776

7877
@Test
@@ -83,23 +82,24 @@ public void testQueryTimeoutException() {
8382
assertNotNull( delegate );
8483

8584
final JDBCException exception = delegate.convert( new SQLException("Client cancelled operation", "57014"), "", "" );
86-
assertTrue( exception instanceof QueryTimeoutException );
85+
assertInstanceOf( QueryTimeoutException.class, exception );
8786
}
8887

8988
/**
9089
* Tests that getForUpdateString(String aliases, LockOptions lockOptions) will return a String
9190
* that will effect the SELECT ... FOR UPDATE OF tableAlias1, ..., tableAliasN
9291
*/
9392
@JiraKey( value = "HHH-5654" )
93+
@Test
9494
public void testGetForUpdateStringWithAliasesAndLockOptions() {
9595
PostgreSQLDialect dialect = new PostgreSQLDialect();
9696
LockOptions lockOptions = new LockOptions( LockMode.PESSIMISTIC_WRITE );
9797

9898
String forUpdateClause = dialect.getForUpdateString("tableAlias1", lockOptions);
99-
assertEquals( "for update of tableAlias1", forUpdateClause );
99+
assertEquals( " for no key update of tableAlias1", forUpdateClause );
100100

101101
forUpdateClause = dialect.getForUpdateString("tableAlias1,tableAlias2", lockOptions);
102-
assertEquals("for update of tableAlias1,tableAlias2", forUpdateClause);
102+
assertEquals(" for no key update of tableAlias1,tableAlias2", forUpdateClause);
103103
}
104104

105105
@Test
@@ -121,7 +121,7 @@ public void testMessageException() {
121121
fail( "Expected UnsupportedOperationException" );
122122
}
123123
catch (Exception e) {
124-
assertTrue( e instanceof UnsupportedOperationException );
124+
assertInstanceOf( UnsupportedOperationException.class, e );
125125
assertEquals( "PostgreSQL only supports accessing REF_CURSOR parameters by position", e.getMessage() );
126126
}
127127
}

0 commit comments

Comments
 (0)