Skip to content

Commit e04c89f

Browse files
committed
HHH-19846 Drop JUnit 4 usage
1 parent 3f2426c commit e04c89f

File tree

3 files changed

+121
-140
lines changed

3 files changed

+121
-140
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/lob/AbstractLobTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,13 @@ public void testBlob(SessionFactoryScope scope) {
120120
}
121121

122122
@Test
123-
@SkipForDialect(dialectClass = SybaseDialect.class)
123+
@SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true)
124124
public void testBinary(SessionFactoryScope scope) {
125125

126126
C cc = createCompiledCode();
127127
byte[] metadata = new byte[2];
128-
metadata[0] = 3;
129-
metadata[1] = 0;
128+
metadata[0] = ( byte ) 3;
129+
metadata[1] = ( byte ) 0;
130130
cc.setMetadata( metadata );
131131

132132
scope.inTransaction( session ->

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/lob/MaterializedBlobTest.java

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

7-
import java.util.Arrays;
8-
9-
import org.hibernate.Session;
107
import org.hibernate.dialect.CockroachDialect;
118
import org.hibernate.metamodel.mapping.AttributeMapping;
129
import org.hibernate.metamodel.mapping.BasicValuedModelPart;
1310
import org.hibernate.metamodel.mapping.JdbcMapping;
1411
import org.hibernate.persister.entity.EntityPersister;
12+
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
13+
import org.hibernate.testing.orm.junit.DomainModel;
14+
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
15+
import org.hibernate.testing.orm.junit.SessionFactory;
16+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
17+
import org.hibernate.testing.orm.junit.SkipForDialect;
1518
import org.hibernate.type.descriptor.java.PrimitiveByteArrayJavaType;
1619
import org.hibernate.type.descriptor.jdbc.BlobJdbcType;
17-
18-
import org.hibernate.testing.DialectChecks;
19-
import org.hibernate.testing.RequiresDialectFeature;
20-
import org.hibernate.testing.SkipForDialect;
21-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
22-
import org.junit.Test;
20+
import org.junit.jupiter.api.Test;
2321

2422
import static org.assertj.core.api.Assertions.assertThat;
25-
import static org.junit.Assert.assertTrue;
2623

2724
/**
2825
* @author Steve Ebersole
2926
*/
30-
@RequiresDialectFeature(DialectChecks.SupportsExpectedLobUsagePattern.class)
31-
public class MaterializedBlobTest extends BaseCoreFunctionalTestCase {
32-
@Override
33-
protected Class<?>[] getAnnotatedClasses() {
34-
return new Class<?>[] { MaterializedBlobEntity.class };
35-
}
27+
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsExpectedLobUsagePattern.class)
28+
@DomainModel(
29+
annotatedClasses = {
30+
MaterializedBlobEntity.class
31+
}
32+
)
33+
@SessionFactory
34+
public class MaterializedBlobTest {
3635

3736
@Test
38-
@SkipForDialect(value = CockroachDialect.class, comment = "Blob in CockroachDB is same as a varbinary, to assertions will fail")
39-
public void testTypeSelection() {
40-
final EntityPersister entityDescriptor = sessionFactory().getRuntimeMetamodels()
37+
@SkipForDialect(dialectClass = CockroachDialect.class,
38+
reason = "Blob in CockroachDB is same as a varbinary, to assertions will fail")
39+
public void testTypeSelection(SessionFactoryScope scope) {
40+
final EntityPersister entityDescriptor = scope.getSessionFactory().getRuntimeMetamodels()
4141
.getMappingMetamodel()
4242
.getEntityDescriptor( MaterializedBlobEntity.class.getName() );
4343
final AttributeMapping theBytesAttr = entityDescriptor.findAttributeMapping( "theBytes" );
4444
assertThat( theBytesAttr ).isInstanceOf( BasicValuedModelPart.class );
45-
final JdbcMapping mapping = ( (BasicValuedModelPart) theBytesAttr ).getJdbcMapping();
46-
assertTrue( mapping.getJavaTypeDescriptor() instanceof PrimitiveByteArrayJavaType );
47-
assertTrue( mapping.getJdbcType() instanceof BlobJdbcType );
45+
final JdbcMapping mapping = ((BasicValuedModelPart) theBytesAttr).getJdbcMapping();
46+
assertThat( mapping.getJavaTypeDescriptor() ).isInstanceOf( PrimitiveByteArrayJavaType.class );
47+
assertThat( mapping.getJdbcType() ).isInstanceOf( BlobJdbcType.class );
4848
}
4949

5050
@Test
51-
public void testSaving() {
51+
public void testSaving(SessionFactoryScope scope) {
5252
byte[] testData = "test data".getBytes();
5353

54-
Session session = openSession();
55-
session.beginTransaction();
56-
MaterializedBlobEntity entity = new MaterializedBlobEntity( "test", testData );
57-
session.persist( entity );
58-
session.getTransaction().commit();
59-
session.close();
54+
MaterializedBlobEntity e = new MaterializedBlobEntity( "test", testData );
55+
scope.inTransaction(
56+
session ->
57+
session.persist( e )
58+
);
6059

61-
session = openSession();
62-
session.beginTransaction();
63-
entity = session.get( MaterializedBlobEntity.class, entity.getId() );
64-
assertTrue( Arrays.equals( testData, entity.getTheBytes() ) );
65-
session.remove( entity );
66-
session.getTransaction().commit();
67-
session.close();
60+
scope.inTransaction(
61+
session -> {
62+
MaterializedBlobEntity entity = session.find( MaterializedBlobEntity.class, e.getId() );
63+
assertThat( entity.getTheBytes() ).isEqualTo( testData );
64+
session.remove( entity );
65+
}
66+
);
6867
}
6968
}

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/lob/TextTest.java

Lines changed: 83 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,15 @@
44
*/
55
package org.hibernate.orm.test.annotations.lob;
66

7-
import java.util.Arrays;
8-
9-
import org.hibernate.Session;
107
import org.hibernate.dialect.SQLServerDialect;
118
import org.hibernate.dialect.SybaseDialect;
9+
import org.hibernate.testing.orm.junit.DomainModel;
10+
import org.hibernate.testing.orm.junit.RequiresDialect;
11+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
12+
import org.junit.jupiter.api.Test;
1213

13-
import org.hibernate.testing.RequiresDialect;
14-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
15-
import org.junit.Assert;
16-
import org.junit.Test;
17-
import junit.framework.AssertionFailedError;
14+
import static org.assertj.core.api.Assertions.assertThat;
1815

19-
import static org.junit.Assert.assertNull;
2016

2117
/**
2218
* Tests eager materialization and mutation of long strings.
@@ -25,123 +21,109 @@
2521
*/
2622
@RequiresDialect(SQLServerDialect.class)
2723
@RequiresDialect(SybaseDialect.class)
28-
public class TextTest extends BaseCoreFunctionalTestCase {
29-
30-
@Override
31-
protected Class<?>[] getAnnotatedClasses() {
32-
return new Class[] { LongStringHolder.class };
33-
}
24+
@DomainModel(
25+
annotatedPackageNames = "org.hibernate.orm.test.annotations.lob",
26+
annotatedClasses = {
27+
LongStringHolder.class
28+
}
29+
)
30+
public class TextTest {
3431

3532
private static final int LONG_STRING_SIZE = 10000;
3633

3734
@Test
38-
public void testBoundedLongStringAccess() {
39-
String original = buildRecursively(LONG_STRING_SIZE, 'x');
40-
String changed = buildRecursively(LONG_STRING_SIZE, 'y');
41-
42-
Session s = openSession();
43-
s.beginTransaction();
44-
LongStringHolder entity = new LongStringHolder();
45-
s.persist(entity);
46-
s.getTransaction().commit();
47-
s.close();
48-
49-
s = openSession();
50-
s.beginTransaction();
51-
entity = (LongStringHolder) s.get(LongStringHolder.class, entity
52-
.getId());
53-
assertNull(entity.getLongString());
54-
assertNull(entity.getName());
55-
assertNull(entity.getWhatEver());
56-
entity.setLongString(original);
57-
entity.setName(original.toCharArray());
58-
entity.setWhatEver(wrapPrimitive(original.toCharArray()));
59-
s.getTransaction().commit();
60-
s.close();
61-
62-
s = openSession();
63-
s.beginTransaction();
64-
entity = (LongStringHolder) s.get(LongStringHolder.class, entity
65-
.getId());
66-
Assert.assertEquals( LONG_STRING_SIZE, entity.getLongString().length() );
67-
Assert.assertEquals( original, entity.getLongString() );
68-
Assert.assertNotNull( entity.getName() );
69-
Assert.assertEquals( LONG_STRING_SIZE, entity.getName().length );
70-
assertEquals( original.toCharArray(), entity.getName() );
71-
Assert.assertNotNull( entity.getWhatEver() );
72-
Assert.assertEquals( LONG_STRING_SIZE, entity.getWhatEver().length );
73-
assertEquals( original.toCharArray(), unwrapNonPrimitive( entity.getWhatEver() ) );
74-
entity.setLongString(changed);
75-
entity.setName(changed.toCharArray());
76-
entity.setWhatEver(wrapPrimitive(changed.toCharArray()));
77-
s.getTransaction().commit();
78-
s.close();
79-
80-
s = openSession();
81-
s.beginTransaction();
82-
entity = (LongStringHolder) s.get(LongStringHolder.class, entity
83-
.getId());
84-
Assert.assertEquals( LONG_STRING_SIZE, entity.getLongString().length() );
85-
Assert.assertEquals( changed, entity.getLongString() );
86-
Assert.assertNotNull( entity.getName() );
87-
Assert.assertEquals( LONG_STRING_SIZE, entity.getName().length );
88-
assertEquals( changed.toCharArray(), entity.getName() );
89-
Assert.assertNotNull( entity.getWhatEver() );
90-
Assert.assertEquals( LONG_STRING_SIZE, entity.getWhatEver().length );
91-
assertEquals( changed.toCharArray(), unwrapNonPrimitive( entity.getWhatEver() ) );
92-
entity.setLongString(null);
93-
entity.setName(null);
94-
entity.setWhatEver(null);
95-
s.getTransaction().commit();
96-
s.close();
97-
98-
s = openSession();
99-
s.beginTransaction();
100-
entity = (LongStringHolder) s.get(LongStringHolder.class, entity
101-
.getId());
102-
assertNull(entity.getLongString());
103-
assertNull(entity.getName());
104-
assertNull(entity.getWhatEver());
105-
s.remove(entity);
106-
s.getTransaction().commit();
107-
s.close();
35+
public void testBoundedLongStringAccess(SessionFactoryScope scope) {
36+
String original = buildRecursively( LONG_STRING_SIZE, 'x' );
37+
String changed = buildRecursively( LONG_STRING_SIZE, 'y' );
38+
39+
LongStringHolder e = new LongStringHolder();
40+
scope.inTransaction(
41+
session ->
42+
session.persist( e )
43+
);
44+
45+
scope.inTransaction(
46+
session -> {
47+
LongStringHolder entity = session.find( LongStringHolder.class, e.getId() );
48+
assertThat( entity.getLongString() ).isNull();
49+
assertThat( entity.getName() ).isNull();
50+
assertThat( entity.getWhatEver() ).isNull();
51+
entity.setLongString( original );
52+
entity.setName( original.toCharArray() );
53+
entity.setWhatEver( wrapPrimitive( original.toCharArray() ) );
54+
}
55+
);
56+
57+
58+
scope.inTransaction(
59+
session -> {
60+
LongStringHolder entity = session.find( LongStringHolder.class, e.getId() );
61+
assertThat( entity.getLongString().length() ).isEqualTo( LONG_STRING_SIZE );
62+
assertThat( entity.getLongString() ).isEqualTo( original );
63+
assertThat( entity.getName() ).isNotNull();
64+
assertThat( entity.getName().length ).isEqualTo( LONG_STRING_SIZE );
65+
assertThat( entity.getName() ).isEqualTo( original.toCharArray() );
66+
assertThat( entity.getWhatEver() ).isNotNull();
67+
assertThat( entity.getWhatEver().length ).isEqualTo( LONG_STRING_SIZE );
68+
assertThat( unwrapNonPrimitive( entity.getWhatEver() ) ).isEqualTo( original.toCharArray() );
69+
entity.setLongString( changed );
70+
entity.setName( changed.toCharArray() );
71+
entity.setWhatEver( wrapPrimitive( changed.toCharArray() ) );
72+
}
73+
);
74+
75+
scope.inTransaction(
76+
session -> {
77+
LongStringHolder entity = session.find( LongStringHolder.class, e.getId() );
78+
assertThat( entity.getLongString().length() ).isEqualTo( LONG_STRING_SIZE );
79+
assertThat( entity.getLongString() ).isEqualTo( changed );
80+
assertThat( entity.getName() ).isNotNull();
81+
assertThat( entity.getName().length ).isEqualTo( LONG_STRING_SIZE );
82+
assertThat( entity.getName() ).isEqualTo( changed.toCharArray() );
83+
assertThat( entity.getWhatEver() ).isNotNull();
84+
assertThat( entity.getWhatEver().length ).isEqualTo( LONG_STRING_SIZE );
85+
assertThat( unwrapNonPrimitive( entity.getWhatEver() ) ).isEqualTo( changed.toCharArray() );
86+
entity.setLongString( null );
87+
entity.setName( null );
88+
entity.setWhatEver( null );
89+
}
90+
);
91+
92+
scope.inTransaction(
93+
session -> {
94+
LongStringHolder entity = session.find( LongStringHolder.class, e.getId() );
95+
assertThat( entity.getLongString() ).isNull();
96+
assertThat( entity.getName() ).isNull();
97+
assertThat( entity.getWhatEver() ).isNull();
98+
session.remove( entity );
99+
}
100+
);
108101
}
109102

110-
public static void assertEquals(char[] val1, char[] val2) {
111-
if ( !Arrays.equals( val1, val2 ) ) {
112-
throw new AssertionFailedError("byte arrays did not match");
113-
}
114-
}
115103

116104
private String buildRecursively(int size, char baseChar) {
117105
StringBuilder buff = new StringBuilder();
118-
for (int i = 0; i < size; i++) {
119-
buff.append(baseChar);
106+
for ( int i = 0; i < size; i++ ) {
107+
buff.append( baseChar );
120108
}
121109
return buff.toString();
122110
}
123111

124112
private Character[] wrapPrimitive(char[] bytes) {
125113
int length = bytes.length;
126114
Character[] result = new Character[length];
127-
for (int index = 0; index < length; index++) {
128-
result[index] = Character.valueOf(bytes[index]);
115+
for ( int index = 0; index < length; index++ ) {
116+
result[index] = Character.valueOf( bytes[index] );
129117
}
130118
return result;
131119
}
132120

133121
private char[] unwrapNonPrimitive(Character[] bytes) {
134122
int length = bytes.length;
135123
char[] result = new char[length];
136-
for (int i = 0; i < length; i++) {
124+
for ( int i = 0; i < length; i++ ) {
137125
result[i] = bytes[i].charValue();
138126
}
139127
return result;
140128
}
141-
142-
@Override
143-
protected String[] getAnnotatedPackages() {
144-
return new String[] { "org.hibernate.orm.test.annotations.lob" };
145-
}
146-
147129
}

0 commit comments

Comments
 (0)