Skip to content

Commit 514fdfa

Browse files
committed
HHH-19916 More drop JUnit 4 usage work
1 parent b901a84 commit 514fdfa

File tree

7 files changed

+405
-467
lines changed

7 files changed

+405
-467
lines changed

hibernate-community-dialects/src/test/java/org/hibernate/community/dialect/AltibaseDialectTestCase.java

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,62 @@
44
*/
55
package org.hibernate.community.dialect;
66

7-
import java.util.Locale;
8-
97
import org.hibernate.dialect.DatabaseVersion;
108
import org.hibernate.dialect.Dialect;
119
import org.hibernate.orm.test.dialect.LimitQueryOptions;
1210
import org.hibernate.query.spi.Limit;
11+
import org.hibernate.testing.orm.junit.BaseUnitTest;
12+
import org.junit.jupiter.api.AfterEach;
13+
import org.junit.jupiter.api.BeforeEach;
14+
import org.junit.jupiter.api.Test;
15+
16+
import java.util.Locale;
1317

14-
import org.hibernate.testing.junit4.BaseUnitTestCase;
15-
import org.junit.After;
16-
import org.junit.Before;
17-
import org.junit.Test;
18+
import static org.assertj.core.api.Assertions.assertThat;
1819

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertTrue;
2120

2221
/**
2322
* Unit test of the behavior of the AltibaseDialect utility methods
2423
*
2524
* @author Geoffrey Park
2625
*/
27-
public class AltibaseDialectTestCase extends BaseUnitTestCase {
26+
@BaseUnitTest
27+
public class AltibaseDialectTestCase {
2828
private Dialect dialect;
2929

30-
@Before
30+
@BeforeEach
3131
public void setUp() {
32-
dialect = new AltibaseDialect( DatabaseVersion.make( 7, 3 ));
32+
dialect = new AltibaseDialect( DatabaseVersion.make( 7, 3 ) );
3333
}
3434

35-
@After
35+
@AfterEach
3636
public void tearDown() {
3737
dialect = null;
3838
}
3939

4040
@Test
4141
public void testSupportLimits() {
42-
assertTrue(dialect.getLimitHandler().supportsLimit());
42+
assertThat( dialect.getLimitHandler().supportsLimit() ).isTrue();
4343
}
4444

4545
@Test
4646
public void testSelectWithLimitOnly() {
47-
assertEquals( "select c1, c2 from t1 order by c1, c2 desc limit ?",
48-
withLimit("select c1, c2 from t1 order by c1, c2 desc",
49-
toRowSelection( 0, 15 ) ).toLowerCase( Locale.ROOT));
47+
assertThat( withLimit( "select c1, c2 from t1 order by c1, c2 desc",
48+
toRowSelection( 0, 15 ) ).toLowerCase( Locale.ROOT ) )
49+
.isEqualTo( "select c1, c2 from t1 order by c1, c2 desc limit ?" );
5050
}
5151

5252
@Test
5353
public void testSelectWithOffsetLimit() {
54-
assertEquals( "select c1, c2 from t1 order by c1, c2 desc limit 1+?,?",
55-
withLimit("select c1, c2 from t1 order by c1, c2 desc",
56-
toRowSelection( 5, 15 ) ).toLowerCase(Locale.ROOT));
54+
assertThat( withLimit( "select c1, c2 from t1 order by c1, c2 desc",
55+
toRowSelection( 5, 15 ) ).toLowerCase( Locale.ROOT ) )
56+
.isEqualTo( "select c1, c2 from t1 order by c1, c2 desc limit 1+?,?" );
5757
}
5858

5959
@Test
6060
public void testSelectWithNoLimit() {
61-
assertEquals( "select c1, c2 from t1 order by c1, c2 desc",
62-
withLimit( "select c1, c2 from t1 order by c1, c2 desc",
63-
null ).toLowerCase(Locale.ROOT));
61+
assertThat( withLimit( "select c1, c2 from t1 order by c1, c2 desc", null ).toLowerCase( Locale.ROOT ) )
62+
.isEqualTo( "select c1, c2 from t1 order by c1, c2 desc" );
6463
}
6564

6665
private String withLimit(String sql, Limit limit) {

hibernate-community-dialects/src/test/java/org/hibernate/community/dialect/CommunityDialectFactoryTest.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,34 @@
44
*/
55
package org.hibernate.community.dialect;
66

7-
import java.util.HashMap;
8-
97
import org.hibernate.boot.registry.BootstrapServiceRegistry;
108
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
119
import org.hibernate.boot.registry.StandardServiceRegistry;
10+
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
1211
import org.hibernate.dialect.Dialect;
1312
import org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl;
1413
import org.hibernate.engine.jdbc.dialect.spi.DialectResolver;
1514
import org.hibernate.orm.test.dialect.resolver.TestingDialectResolutionInfo;
1615
import org.hibernate.service.spi.ServiceRegistryImplementor;
17-
18-
import org.hibernate.testing.junit4.BaseUnitTestCase;
16+
import org.hibernate.testing.orm.junit.BaseUnitTest;
1917
import org.hibernate.testing.util.ServiceRegistryUtil;
20-
import org.junit.Before;
21-
import org.junit.Test;
18+
import org.junit.jupiter.api.AfterEach;
19+
import org.junit.jupiter.api.BeforeEach;
20+
import org.junit.jupiter.api.Test;
2221

23-
import static org.junit.Assert.assertEquals;
22+
import java.util.HashMap;
23+
24+
import static org.assertj.core.api.Assertions.assertThat;
2425

2526
/**
2627
* @author Steve Ebersole
2728
*/
28-
public class CommunityDialectFactoryTest extends BaseUnitTestCase {
29+
@BaseUnitTest
30+
public class CommunityDialectFactoryTest {
2931
private StandardServiceRegistry registry;
3032
private DialectFactoryImpl dialectFactory;
3133

32-
@Before
34+
@BeforeEach
3335
public void setUp() {
3436
final BootstrapServiceRegistry bootReg = new BootstrapServiceRegistryBuilder().applyClassLoader(
3537
CommunityDialectFactoryTest.class.getClassLoader()
@@ -40,6 +42,13 @@ public void setUp() {
4042
dialectFactory.injectServices( (ServiceRegistryImplementor) registry );
4143
}
4244

45+
@AfterEach
46+
public void tearDown() {
47+
if ( registry != null ) {
48+
StandardServiceRegistryBuilder.destroy( registry );
49+
}
50+
}
51+
4352
@Test
4453
public void testPreregisteredDialects() {
4554
DialectResolver resolver = new CommunityDialectResolver();
@@ -77,8 +86,9 @@ private void testDetermination(
7786
dialectFactory.setDialectResolver( resolver );
7887
Dialect resolved = dialectFactory.buildDialect(
7988
new HashMap<>(),
80-
() -> TestingDialectResolutionInfo.forDatabaseInfo( databaseName, driverName, majorVersion, minorVersion )
89+
() -> TestingDialectResolutionInfo.forDatabaseInfo( databaseName, driverName, majorVersion,
90+
minorVersion )
8191
);
82-
assertEquals( expected, resolved.getClass() );
92+
assertThat( resolved.getClass() ).isEqualTo( expected );
8393
}
8494
}

hibernate-community-dialects/src/test/java/org/hibernate/community/dialect/CommunityDialectSelectorTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
package org.hibernate.community.dialect;
66

77
import org.hibernate.dialect.Dialect;
8+
import org.junit.jupiter.api.Test;
9+
10+
import static org.assertj.core.api.Assertions.assertThat;
811

9-
import org.junit.Assert;
10-
import org.junit.Test;
1112

1213
public class CommunityDialectSelectorTest {
1314

@@ -36,8 +37,8 @@ private void testDialectNamingResolution(final Class<?> dialectClass) {
3637
simpleName = simpleName.substring( 0, simpleName.length() - "Dialect".length() );
3738
}
3839
Class<? extends Dialect> aClass = strategySelector.resolve( simpleName );
39-
Assert.assertNotNull( aClass );
40-
Assert.assertEquals( dialectClass, aClass );
40+
assertThat( aClass ).isNotNull();
41+
assertThat( aClass ).isEqualTo( dialectClass );
4142
}
4243

4344
}

hibernate-community-dialects/src/test/java/org/hibernate/community/dialect/DB2LegacyDialectTestCase.java

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,31 @@
44
*/
55
package org.hibernate.community.dialect;
66

7-
import java.sql.Types;
8-
97
import org.hibernate.engine.jdbc.Size;
108
import org.hibernate.orm.test.dialect.LimitQueryOptions;
119
import org.hibernate.query.spi.Limit;
10+
import org.hibernate.testing.orm.junit.BaseUnitTest;
11+
import org.hibernate.testing.orm.junit.JiraKey;
1212
import org.hibernate.type.spi.TypeConfiguration;
13+
import org.junit.jupiter.api.BeforeEach;
14+
import org.junit.jupiter.api.Test;
1315

14-
import org.hibernate.testing.orm.junit.JiraKey;
15-
import org.hibernate.testing.junit4.BaseUnitTestCase;
16-
import org.junit.Before;
17-
import org.junit.Test;
16+
import java.sql.Types;
1817

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertTrue;
18+
import static org.assertj.core.api.Assertions.assertThat;
2119

2220
/**
2321
* DB2 dialect related test cases
2422
*
2523
* @author Hardy Ferentschik
2624
*/
2725

28-
public class DB2LegacyDialectTestCase extends BaseUnitTestCase {
26+
@BaseUnitTest
27+
public class DB2LegacyDialectTestCase {
2928
private final DB2LegacyDialect dialect = new DB2LegacyDialect();
3029
private TypeConfiguration typeConfiguration;
3130

32-
@Before
31+
@BeforeEach
3332
public void setup() {
3433
typeConfiguration = new TypeConfiguration();
3534
dialect.contributeTypes( () -> typeConfiguration, null );
@@ -39,52 +38,42 @@ public void setup() {
3938
@JiraKey(value = "HHH-6866")
4039
public void testGetDefaultBinaryTypeName() {
4140
String actual = typeConfiguration.getDdlTypeRegistry().getTypeName( Types.BINARY, dialect );
42-
assertEquals(
43-
"The default column length is 255, but char length on DB2 is limited to 254",
44-
"varchar($l) for bit data",
45-
actual
46-
);
41+
assertThat( actual )
42+
.describedAs( "The default column length is 255, but char length on DB2 is limited to 254" )
43+
.isEqualTo( "varchar($l) for bit data" );
4744
}
4845

4946
@Test
5047
@JiraKey(value = "HHH-6866")
5148
public void testGetExplicitBinaryTypeName() {
5249
// lower bound
53-
String actual = typeConfiguration.getDdlTypeRegistry().getTypeName( Types.BINARY, Size.length( 1) );
54-
assertEquals(
55-
"Wrong binary type",
56-
"char(1) for bit data",
57-
actual
58-
);
50+
String actual = typeConfiguration.getDdlTypeRegistry().getTypeName( Types.BINARY, Size.length( 1 ) );
51+
assertThat( actual )
52+
.describedAs( "Wrong binary type" )
53+
.isEqualTo( "char(1) for bit data" );
5954

6055
// upper bound
61-
actual = typeConfiguration.getDdlTypeRegistry().getTypeName( Types.BINARY, Size.length( 254) );
62-
assertEquals(
63-
"Wrong binary type. 254 is the max length in DB2",
64-
"char(254) for bit data",
65-
actual
66-
);
56+
actual = typeConfiguration.getDdlTypeRegistry().getTypeName( Types.BINARY, Size.length( 254 ) );
57+
assertThat( actual )
58+
.describedAs( "Wrong binary type. 254 is the max length in DB2" )
59+
.isEqualTo( "char(254) for bit data" );
6760

6861
// exceeding upper bound
69-
actual = typeConfiguration.getDdlTypeRegistry().getTypeName( Types.BINARY, Size.length( 255) );
70-
assertEquals(
71-
"Wrong binary type. Should be varchar for length > 254",
72-
"varchar(255) for bit data",
73-
actual
74-
);
62+
actual = typeConfiguration.getDdlTypeRegistry().getTypeName( Types.BINARY, Size.length( 255 ) );
63+
assertThat( actual )
64+
.describedAs( "Wrong binary type. Should be varchar for length > 254" )
65+
.isEqualTo( "varchar(255) for bit data" );
7566
}
7667

7768
@Test
7869
@JiraKey(value = "HHH-12369")
7970
public void testIntegerOverflowForMaxResults() {
8071
Limit rowSelection = new Limit();
81-
rowSelection.setFirstRow(1);
82-
rowSelection.setMaxRows(Integer.MAX_VALUE);
72+
rowSelection.setFirstRow( 1 );
73+
rowSelection.setMaxRows( Integer.MAX_VALUE );
8374
String sql = dialect.getLimitHandler().processSql( "select a.id from tbl_a a order by a.id", -1, null,
8475
new LimitQueryOptions( rowSelection ) );
85-
assertTrue(
86-
"Integer overflow for max rows in: " + sql,
87-
sql.contains("fetch first 2147483647 rows only")
88-
);
76+
assertThat( sql ).describedAs( "Integer overflow for max rows in: " + sql )
77+
.contains( "fetch first 2147483647 rows only" );
8978
}
9079
}

0 commit comments

Comments
 (0)