Skip to content

Commit 319ad1f

Browse files
committed
HHH-19846 - Drop JUnit 4 usage
Cannot convert... * 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
1 parent 8ed995a commit 319ad1f

File tree

6 files changed

+130
-154
lines changed

6 files changed

+130
-154
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/util/BytesHelperTest.java

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

7-
import static org.junit.Assert.assertArrayEquals;
8-
import static org.junit.Assert.assertEquals;
9-
107
import org.hibernate.internal.util.BytesHelper;
11-
import org.hibernate.testing.junit4.BaseUnitTestCase;
12-
import org.junit.Test;
8+
import org.hibernate.testing.orm.junit.BaseUnitTest;
9+
import org.hibernate.testing.orm.junit.ExpectedException;
10+
import org.junit.jupiter.api.Test;
11+
12+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
13+
import static org.junit.jupiter.api.Assertions.assertEquals;
1314

1415
/**
1516
* @author Benoit W
1617
*/
17-
public class BytesHelperTest extends BaseUnitTestCase {
18+
@BaseUnitTest
19+
public class BytesHelperTest {
1820

1921
@Test
2022
public void testAsLongNullArray() {
2123
assertEquals(0, BytesHelper.asLong(null, 0));
2224
}
2325

24-
@Test(expected=IllegalArgumentException.class)
26+
@Test()
27+
@ExpectedException(IllegalArgumentException.class)
2528
public void testAsLongArrayTooSmall() {
2629
byte[] src = new byte[16];
2730
assertEquals(0, BytesHelper.asLong(src, 9));

hibernate-core/src/test/java/org/hibernate/orm/test/util/PropertiesHelperTest.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,29 @@
33
* Copyright Red Hat Inc. and Hibernate Authors
44
*/
55
package org.hibernate.orm.test.util;
6-
import java.util.Properties;
7-
8-
import org.junit.Before;
9-
import org.junit.Test;
106

117
import org.hibernate.internal.util.config.ConfigurationHelper;
12-
import org.hibernate.testing.junit4.BaseUnitTestCase;
8+
import org.hibernate.testing.orm.junit.BaseUnitTest;
9+
import org.junit.jupiter.api.BeforeEach;
10+
import org.junit.jupiter.api.Test;
11+
12+
import java.util.Properties;
1313

14-
import static org.junit.Assert.assertEquals;
15-
import static org.junit.Assert.assertFalse;
16-
import static org.junit.Assert.assertNull;
17-
import static org.junit.Assert.assertTrue;
18-
import static org.junit.Assert.fail;
14+
import static org.junit.jupiter.api.Assertions.assertEquals;
15+
import static org.junit.jupiter.api.Assertions.assertNull;
16+
import static org.junit.jupiter.api.Assertions.assertTrue;
17+
import static org.junit.jupiter.api.Assertions.assertFalse;
18+
import static org.junit.jupiter.api.Assertions.fail;
1919

2020
/**
2121
* @author Steve Ebersole
2222
*/
23-
public class PropertiesHelperTest extends BaseUnitTestCase {
23+
@BaseUnitTest
24+
public class PropertiesHelperTest {
2425
private Properties props;
2526

26-
@Before
27-
public void setUp() throws Exception {
27+
@BeforeEach
28+
public void setUp() {
2829
props = new Properties();
2930

3031
props.setProperty( "my.nonexistent.prop", "${}" );
@@ -58,20 +59,20 @@ public void testPlaceholderReplacement() {
5859
str = ConfigurationHelper.getString( "my.nonexistent.prop", props );
5960
assertNull( str );
6061
str = ConfigurationHelper.getString( "my.string.prop", props, "na" );
61-
assertEquals( "replacement did not occur", "string", str );
62+
assertEquals( "string", str, "replacement did not occur" );
6263
str = ConfigurationHelper.getString( "my.string.prop", props, "did.not.exist" );
63-
assertEquals( "replacement did not occur", "string", str );
64+
assertEquals( "string", str, "replacement did not occur" );
6465

6566
boolean bool = ConfigurationHelper.getBoolean( "my.nonexistent.prop", props );
66-
assertFalse( "non-exists as boolean", bool );
67+
assertFalse( bool, "non-exists as boolean" );
6768
bool = ConfigurationHelper.getBoolean( "my.nonexistent.prop", props, false );
68-
assertFalse( "non-exists as boolean", bool );
69+
assertFalse( bool, "non-exists as boolean" );
6970
bool = ConfigurationHelper.getBoolean( "my.nonexistent.prop", props, true );
70-
assertTrue( "non-exists as boolean", bool );
71+
assertTrue( bool, "non-exists as boolean" );
7172
bool = ConfigurationHelper.getBoolean( "my.boolean.prop", props );
72-
assertTrue( "boolean replacement did not occur", bool );
73+
assertTrue( bool, "boolean replacement did not occur" );
7374
bool = ConfigurationHelper.getBoolean( "my.boolean.prop", props, false );
74-
assertTrue( "boolean replacement did not occur", bool );
75+
assertTrue( bool, "boolean replacement did not occur" );
7576

7677
int i = ConfigurationHelper.getInt( "my.nonexistent.prop", props, -1 );
7778
assertEquals( -1, i );
@@ -81,19 +82,19 @@ public void testPlaceholderReplacement() {
8182
Integer I = ConfigurationHelper.getInteger( "my.nonexistent.prop", props );
8283
assertNull( I );
8384
I = ConfigurationHelper.getInteger( "my.integer.prop", props );
84-
assertEquals( I, new Integer( 1 ) );
85+
assertEquals( Integer.valueOf( 1 ), I );
8586

8687
str = props.getProperty( "partial.prop1" );
87-
assertEquals( "partial replacement (ends)", "tmp/middle/dir/tmp.txt", str );
88+
assertEquals( "tmp/middle/dir/tmp.txt", str, "partial replacement (ends)" );
8889

8990
str = props.getProperty( "partial.prop2" );
90-
assertEquals( "partial replacement (midst)", "basedir/tmp/myfile.txt", str );
91+
assertEquals( "basedir/tmp/myfile.txt", str, "partial replacement (midst)" );
9192
}
9293

9394
@Test
9495
public void testParseExceptions() {
9596
boolean b = ConfigurationHelper.getBoolean( "parse.error", props );
96-
assertFalse( "parse exception case - boolean", b );
97+
assertFalse( b, "parse exception case - boolean" );
9798

9899
try {
99100
ConfigurationHelper.getInt( "parse.error", props, 20 );

hibernate-core/src/test/java/org/hibernate/orm/test/util/RowVersionComparatorTest.java

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

7-
import org.junit.Test;
8-
97
import org.hibernate.internal.util.compare.RowVersionComparator;
10-
import org.hibernate.testing.junit4.BaseUnitTestCase;
8+
import org.hibernate.testing.orm.junit.BaseUnitTest;
9+
import org.junit.jupiter.api.Test;
1110

12-
import static org.junit.Assert.assertEquals;
13-
import static org.junit.Assert.assertTrue;
14-
import static org.junit.Assert.fail;
11+
import static org.junit.jupiter.api.Assertions.assertEquals;
12+
import static org.junit.jupiter.api.Assertions.assertTrue;
13+
import static org.junit.jupiter.api.Assertions.fail;
1514

1615
/**
1716
* @author Gail Badner
1817
*/
19-
public class RowVersionComparatorTest extends BaseUnitTestCase {
18+
@BaseUnitTest
19+
public class RowVersionComparatorTest {
2020

2121
@Test
2222
public void testNull() {
@@ -47,90 +47,68 @@ public void testNull() {
4747

4848
@Test
4949
public void testArraysSameLength() {
50-
assertEquals(
51-
0,
52-
RowVersionComparator.INSTANCE.compare(
53-
new byte[] {},
54-
new byte[] {}
55-
)
56-
);
57-
assertEquals(
58-
0,
59-
RowVersionComparator.INSTANCE.compare(
60-
new byte[] { 1 },
61-
new byte[] { 1 }
62-
)
63-
);
64-
assertEquals(
65-
0,
66-
RowVersionComparator.INSTANCE.compare(
67-
new byte[] { 1, 2 },
68-
new byte[] { 1, 2 }
69-
)
70-
);
71-
assertTrue(
72-
RowVersionComparator.INSTANCE.compare(
73-
new byte[] { 0, 2 },
74-
new byte[] { 1, 2 }
75-
) < 0
76-
);
50+
assertEquals( 0, RowVersionComparator.INSTANCE.compare(
51+
new byte[] {},
52+
new byte[] {}
53+
) );
54+
assertEquals( 0, RowVersionComparator.INSTANCE.compare(
55+
new byte[] { 1 },
56+
new byte[] { 1 }
57+
) );
58+
assertEquals( 0, RowVersionComparator.INSTANCE.compare(
59+
new byte[] { 1, 2 },
60+
new byte[] { 1, 2 }
61+
) );
62+
assertTrue( RowVersionComparator.INSTANCE.compare(
63+
new byte[] { 0, 2 },
64+
new byte[] { 1, 2 }
65+
) < 0 );
7766

78-
assertTrue(
79-
RowVersionComparator.INSTANCE.compare(
80-
new byte[] { 1, 1 },
81-
new byte[] { 1, 2 }
82-
) < 0
83-
);
67+
assertTrue( RowVersionComparator.INSTANCE.compare(
68+
new byte[] { 1, 1 },
69+
new byte[] { 1, 2 }
70+
) < 0 );
8471

8572
assertTrue( RowVersionComparator.INSTANCE.compare(
8673
new byte[] { 2, 2 },
8774
new byte[] { 1, 2 }
88-
) > 0
89-
);
75+
) > 0 );
9076

9177
assertTrue( RowVersionComparator.INSTANCE.compare(
9278
new byte[] { 2, 2 },
9379
new byte[] { 2, 1 }
94-
) > 0
95-
);
80+
) > 0 );
9681
}
9782

9883
@Test
9984
public void testArraysDifferentLength() {
10085
assertTrue( RowVersionComparator.INSTANCE.compare(
10186
new byte[] {},
10287
new byte[] { 1 }
103-
) < 0
104-
);
88+
) < 0 );
10589

10690
assertTrue( RowVersionComparator.INSTANCE.compare(
10791
new byte[] { 1 },
10892
new byte[] {}
109-
) > 0
110-
);
93+
) > 0 );
11194

11295
assertTrue( RowVersionComparator.INSTANCE.compare(
11396
new byte[] { 1 },
11497
new byte[] { 1, 2 }
115-
) < 0
116-
);
98+
) < 0 );
11799
assertTrue( RowVersionComparator.INSTANCE.compare(
118100
new byte[] { 1, 2 },
119101
new byte[] { 1 }
120-
) > 0
121-
);
102+
) > 0 );
122103

123104
assertTrue( RowVersionComparator.INSTANCE.compare(
124105
new byte[] { 2 },
125106
new byte[] { 1, 2 }
126-
) > 0
127-
);
107+
) > 0 );
128108
assertTrue( RowVersionComparator.INSTANCE.compare(
129109
new byte[] { 1, 2 },
130110
new byte[] { 2 }
131-
) < 0
132-
);
133-
111+
) < 0 );
134112
}
135113

136114

hibernate-core/src/test/java/org/hibernate/orm/test/util/SerializationHelperTest.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,47 @@
66
import java.io.InputStream;
77
import java.io.Serializable;
88

9-
import org.junit.After;
10-
import org.junit.Before;
11-
import org.junit.Test;
9+
import org.hibernate.testing.orm.junit.BaseUnitTest;
1210

1311
import org.hibernate.LockMode;
1412
import org.hibernate.bytecode.spi.ByteCodeHelper;
1513
import org.hibernate.internal.util.SerializationHelper;
16-
import org.hibernate.testing.junit4.BaseUnitTestCase;
14+
import org.junit.jupiter.api.AfterEach;
15+
import org.junit.jupiter.api.BeforeEach;
16+
import org.junit.jupiter.api.Test;
1717

18-
import static org.junit.Assert.assertEquals;
19-
import static org.junit.Assert.assertSame;
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertSame;
2020

2121
/**
2222
* This is basically a test to assert the expectations of {@link org.hibernate.type.SerializableType}
2323
* in regards to deserializing bytes from second level caches.
2424
*
2525
* @author Steve Ebersole
2626
*/
27-
public class SerializationHelperTest extends BaseUnitTestCase {
27+
@BaseUnitTest
28+
public class SerializationHelperTest {
2829
private ClassLoader original;
2930
private CustomClassLoader custom;
3031

31-
@Before
32-
public void setUp() throws Exception {
32+
@BeforeEach
33+
public void setUp() {
3334
original = Thread.currentThread().getContextClassLoader();
3435
custom = new CustomClassLoader( original );
3536
Thread.currentThread().setContextClassLoader( custom );
3637
}
3738

38-
@After
39+
@AfterEach
3940
public void tearDown() throws Exception {
4041
Thread.currentThread().setContextClassLoader( original );
42+
custom = null;
4143
}
4244

4345
@Test
4446
public void testSerializeDeserialize() throws Exception {
45-
Class clazz = Thread.currentThread().getContextClassLoader().loadClass(
47+
Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(
4648
"org.hibernate.orm.test.util.SerializableThing" );
47-
Object instance = clazz.newInstance();
49+
Object instance = clazz.getDeclaredConstructor().newInstance();
4850

4951
// SerializableType.toBytes() logic, as called from SerializableType.disassemble()
5052
byte[] bytes = SerializationHelper.serialize( (Serializable) instance );
@@ -59,7 +61,8 @@ public void testSerializeDeserialize() throws Exception {
5961
assertEquals( custom, instance2.getClass().getClassLoader() );
6062
}
6163

62-
public void testSerDeserClassUnknownToCustomLoader() throws Exception {
64+
@Test
65+
public void testSerDeserClassUnknownToCustomLoader() {
6366
Object instance = LockMode.OPTIMISTIC;
6467
assertSame(
6568
SerializationHelper.hibernateClassLoader(),
@@ -84,15 +87,15 @@ public CustomClassLoader(ClassLoader parent) {
8487
super( parent );
8588
}
8689

87-
public Class loadClass(String name) throws ClassNotFoundException {
90+
public Class<?> loadClass(String name) throws ClassNotFoundException {
8891
if ( name.equals( "org.hibernate.LockMode" ) ) {
8992
throw new ClassNotFoundException( "Could not find "+ name );
9093
}
9194
if ( ! name.equals( "org.hibernate.orm.test.util.SerializableThing" ) ) {
9295
return getParent().loadClass( name );
9396
}
9497

95-
Class c = findLoadedClass( name );
98+
Class<?> c = findLoadedClass( name );
9699
if ( c != null ) {
97100
return c;
98101
}

0 commit comments

Comments
 (0)