Skip to content

Commit 2cc9d41

Browse files
committed
HHH-19846 Drop JUnit 4 usage
1 parent f42094e commit 2cc9d41

File tree

5 files changed

+84
-91
lines changed

5 files changed

+84
-91
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/type/Dvd.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright Red Hat Inc. and Hibernate Authors
44
*/
55
package org.hibernate.orm.test.annotations.type;
6+
67
import jakarta.persistence.AttributeOverride;
78
import jakarta.persistence.Column;
89
import jakarta.persistence.EmbeddedId;

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/type/TypeTest.java

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

7-
import org.junit.Test;
7+
import org.hibernate.testing.orm.junit.DomainModel;
8+
import org.hibernate.testing.orm.junit.SessionFactory;
9+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
10+
import org.junit.jupiter.api.Test;
811

9-
import org.hibernate.Session;
10-
import org.hibernate.Transaction;
11-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
12+
import static org.assertj.core.api.Assertions.assertThat;
1213

13-
import static org.junit.Assert.assertNotNull;
1414

1515
/**
1616
* @author Emmanuel Bernard
1717
*/
18-
public class TypeTest extends BaseCoreFunctionalTestCase {
19-
@Test
20-
public void testIdWithMulticolumns() {
21-
Session s;
22-
Transaction tx;
23-
s = openSession();
24-
tx = s.beginTransaction();
25-
Dvd lesOiseaux = new Dvd();
26-
lesOiseaux.setTitle( "Les oiseaux" );
27-
s.persist( lesOiseaux );
28-
s.flush();
29-
assertNotNull( lesOiseaux.getId() );
30-
tx.rollback();
31-
s.close();
32-
}
18+
@DomainModel(
19+
annotatedClasses = {
20+
Dvd.class
21+
}
22+
)
23+
@SessionFactory
24+
public class TypeTest {
3325

34-
@Override
35-
protected Class[] getAnnotatedClasses() {
36-
return new Class[]{ Dvd.class };
26+
@Test
27+
public void testIdWithMulticolumns(SessionFactoryScope scope) {
28+
scope.inTransaction(
29+
session -> {
30+
Dvd lesOiseaux = new Dvd();
31+
lesOiseaux.setTitle( "Les oiseaux" );
32+
session.persist( lesOiseaux );
33+
session.flush();
34+
assertThat( lesOiseaux.getId() ).isNotNull();
35+
}
36+
);
3737
}
3838
}

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/uniqueconstraint/UniqueConstraintThrowsConstraintViolationExceptionTest.java

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,56 +10,43 @@
1010
import jakarta.persistence.GeneratedValue;
1111
import jakarta.persistence.GenerationType;
1212
import jakarta.persistence.Id;
13-
import jakarta.persistence.PersistenceException;
1413
import jakarta.persistence.Table;
15-
1614
import org.hibernate.exception.ConstraintViolationException;
17-
15+
import org.hibernate.testing.orm.junit.DomainModel;
1816
import org.hibernate.testing.orm.junit.JiraKey;
19-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
20-
import org.junit.Test;
17+
import org.hibernate.testing.orm.junit.SessionFactory;
18+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
19+
import org.junit.jupiter.api.Test;
20+
21+
import static org.junit.jupiter.api.Assertions.assertThrows;
2122

22-
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
23-
import static org.junit.Assert.assertEquals;
24-
import static org.junit.Assert.fail;
2523

2624
/**
2725
* @author Vlad Mihalcea
2826
*/
2927
@JiraKey(value = "HHH-11236")
30-
public class UniqueConstraintThrowsConstraintViolationExceptionTest extends BaseCoreFunctionalTestCase {
28+
@DomainModel(
29+
annotatedClasses = {
30+
UniqueConstraintThrowsConstraintViolationExceptionTest.Customer.class
31+
}
32+
)
33+
@SessionFactory
34+
public class UniqueConstraintThrowsConstraintViolationExceptionTest {
3135

32-
@Override
33-
protected Class<?>[] getAnnotatedClasses() {
34-
return new Class[] { Customer.class };
35-
}
3636

3737
@Test
38-
public void testUniqueConstraintWithEmptyColumnName() {
39-
doInHibernate( this::sessionFactory, session -> {
38+
public void testUniqueConstraintWithEmptyColumnName(SessionFactoryScope scope) {
39+
scope.inTransaction( session -> {
4040
Customer customer1 = new Customer();
4141
customer1.customerId = "123";
4242
session.persist( customer1 );
4343
} );
44-
try {
45-
doInHibernate( this::sessionFactory, session -> {
46-
Customer customer1 = new Customer();
47-
customer1.customerId = "123";
48-
session.persist( customer1 );
49-
} );
50-
fail( "Should throw" );
51-
}
52-
catch ( PersistenceException e ) {
53-
assertEquals(
54-
ConstraintViolationException.class,
55-
e.getClass()
56-
);
57-
}
58-
}
5944

60-
@Override
61-
protected boolean isCleanupTestDataRequired() {
62-
return true;
45+
assertThrows( ConstraintViolationException.class, () -> scope.inTransaction( session -> {
46+
Customer customer1 = new Customer();
47+
customer1.customerId = "123";
48+
session.persist( customer1 );
49+
} ) );
6350
}
6451

6552
@Entity(name = "Customer")

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/uniqueconstraint/UniqueConstraintUnitTests.java

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
*/
55
package org.hibernate.orm.test.annotations.uniqueconstraint;
66

7-
import java.util.HashSet;
8-
import java.util.Set;
97
import jakarta.persistence.CollectionTable;
108
import jakarta.persistence.Column;
119
import jakarta.persistence.ElementCollection;
@@ -16,29 +14,31 @@
1614
import jakarta.persistence.JoinColumn;
1715
import jakarta.persistence.Table;
1816
import jakarta.persistence.UniqueConstraint;
19-
2017
import org.hibernate.AnnotationException;
2118
import org.hibernate.boot.Metadata;
2219
import org.hibernate.boot.MetadataSources;
2320
import org.hibernate.boot.registry.StandardServiceRegistry;
2421
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
25-
22+
import org.hibernate.testing.orm.junit.BaseUnitTest;
2623
import org.hibernate.testing.orm.junit.JiraKey;
27-
import org.hibernate.testing.junit4.BaseUnitTestCase;
2824
import org.hibernate.testing.util.ServiceRegistryUtil;
29-
import org.junit.Test;
25+
import org.junit.jupiter.api.Test;
26+
27+
import java.util.HashSet;
28+
import java.util.Set;
29+
30+
import static org.assertj.core.api.Assertions.assertThat;
31+
import static org.assertj.core.api.Fail.fail;
3032

31-
import static org.junit.Assert.assertFalse;
32-
import static org.junit.Assert.assertTrue;
33-
import static org.junit.Assert.fail;
3433

3534
/**
3635
* @author Steve Ebersole
3736
*/
38-
public class UniqueConstraintUnitTests extends BaseUnitTestCase {
37+
@BaseUnitTest
38+
public class UniqueConstraintUnitTests {
3939

4040
@Test
41-
@JiraKey( value = "HHH-8026" )
41+
@JiraKey(value = "HHH-8026")
4242
public void testUnNamedConstraints() {
4343
StandardServiceRegistry ssr = ServiceRegistryUtil.serviceRegistry();
4444

@@ -59,25 +59,24 @@ else if ( table.getName().equals( "UniqueNoNameB" ) ) {
5959
}
6060
}
6161

62-
assertTrue( "Could not find the expected tables.", tableA != null && tableB != null );
63-
assertFalse(
64-
tableA.getUniqueKeys().values().iterator().next().getName().equals(
65-
tableB.getUniqueKeys().values().iterator().next().getName()
66-
)
67-
);
62+
assertThat( tableA != null && tableB != null )
63+
.describedAs( "Could not find the expected tables." )
64+
.isTrue();
65+
assertThat( tableA.getUniqueKeys().values().iterator().next().getName() )
66+
.isNotEqualTo( tableB.getUniqueKeys().values().iterator().next().getName() );
6867
}
6968
finally {
7069
StandardServiceRegistryBuilder.destroy( ssr );
7170
}
7271
}
7372

7473
@Test
75-
@JiraKey( value = "HHH-8537" )
74+
@JiraKey(value = "HHH-8537")
7675
public void testNonExistentColumn() {
7776
StandardServiceRegistry ssr = ServiceRegistryUtil.serviceRegistry();
7877

7978
try {
80-
final Metadata metadata = new MetadataSources( ssr )
79+
new MetadataSources( ssr )
8180
.addAnnotatedClass( UniqueNoNameA.class )
8281
.addAnnotatedClass( UniqueNoNameB.class )
8382
.buildMetadata();
@@ -94,8 +93,8 @@ public void testNonExistentColumn() {
9493
}
9594

9695
@Entity
97-
@Table( name = "UniqueNoNameA",
98-
uniqueConstraints = {@UniqueConstraint(columnNames={"name"})})
96+
@Table(name = "UniqueNoNameA",
97+
uniqueConstraints = {@UniqueConstraint(columnNames = {"name"})})
9998
public static class UniqueNoNameA {
10099
@Id
101100
@GeneratedValue
@@ -105,8 +104,8 @@ public static class UniqueNoNameA {
105104
}
106105

107106
@Entity
108-
@Table( name = "UniqueNoNameB",
109-
uniqueConstraints = {@UniqueConstraint(columnNames={"name"})})
107+
@Table(name = "UniqueNoNameB",
108+
uniqueConstraints = {@UniqueConstraint(columnNames = {"name"})})
110109
public static class UniqueNoNameB {
111110
@Id
112111
@GeneratedValue
@@ -125,9 +124,9 @@ public static class UniqueColumnDoesNotExist {
125124
name = "tbl_strings",
126125
joinColumns = @JoinColumn(name = "fk", nullable = false),
127126
// the failure required at least 1 columnName to be correct -- all incorrect wouldn't reproduce
128-
uniqueConstraints = @UniqueConstraint(columnNames = { "fk", "doesnotexist" })
127+
uniqueConstraints = @UniqueConstraint(columnNames = {"fk", "doesnotexist"})
129128
)
130129
@Column(name = "string", nullable = false)
131-
public Set<String> strings = new HashSet<String>();
130+
public Set<String> strings = new HashSet<>();
132131
}
133132
}

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/uniqueconstraint/UniqueConstraintValidationTest.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,43 @@
44
*/
55
package org.hibernate.orm.test.annotations.uniqueconstraint;
66

7-
import java.io.Serializable;
87
import jakarta.persistence.Entity;
98
import jakarta.persistence.Id;
109
import jakarta.persistence.Table;
1110
import jakarta.persistence.UniqueConstraint;
12-
1311
import org.hibernate.AnnotationException;
1412
import org.hibernate.boot.MetadataSources;
1513
import org.hibernate.boot.registry.StandardServiceRegistry;
1614
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
17-
15+
import org.hibernate.testing.orm.junit.BaseUnitTest;
1816
import org.hibernate.testing.orm.junit.JiraKey;
19-
import org.hibernate.testing.junit4.BaseUnitTestCase;
2017
import org.hibernate.testing.util.ServiceRegistryUtil;
21-
import org.junit.Test;
18+
import org.junit.jupiter.api.Test;
19+
20+
import java.io.Serializable;
21+
22+
import static org.junit.jupiter.api.Assertions.assertThrows;
2223

2324
/**
2425
* @author Nikolay Shestakov
2526
*
2627
*/
27-
public class UniqueConstraintValidationTest extends BaseUnitTestCase {
28+
@BaseUnitTest
29+
public class UniqueConstraintValidationTest {
2830

29-
@Test(expected = AnnotationException.class)
31+
@Test
3032
@JiraKey(value = "HHH-4084")
3133
public void testUniqueConstraintWithEmptyColumnName() {
32-
buildSessionFactory(EmptyColumnNameEntity.class);
34+
assertThrows( AnnotationException.class, () ->
35+
buildSessionFactory( EmptyColumnNameEntity.class )
36+
);
3337
}
3438

35-
@Test(expected = AnnotationException.class)
39+
@Test
3640
public void testUniqueConstraintWithEmptyColumnNameList() {
37-
buildSessionFactory(EmptyColumnNameListEntity.class);
41+
assertThrows( AnnotationException.class, () ->
42+
buildSessionFactory( EmptyColumnNameListEntity.class )
43+
);
3844
}
3945

4046
@Test

0 commit comments

Comments
 (0)