Skip to content

Commit 3cd466e

Browse files
committed
HHH-19846 Drop JUnit 4 usage
1 parent 4451d08 commit 3cd466e

File tree

2 files changed

+57
-51
lines changed

2 files changed

+57
-51
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/constraint/ForeignKeyConstraintMapsIdTest.java

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,50 @@
1111
import jakarta.persistence.JoinColumn;
1212
import jakarta.persistence.MapsId;
1313
import jakarta.persistence.OneToOne;
14-
1514
import org.hibernate.boot.model.relational.Namespace;
15+
import org.hibernate.boot.spi.MetadataImplementor;
1616
import org.hibernate.mapping.Table;
17-
17+
import org.hibernate.testing.orm.junit.DomainModel;
1818
import org.hibernate.testing.orm.junit.JiraKey;
19-
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
20-
import org.junit.Test;
19+
import org.hibernate.testing.orm.junit.SessionFactory;
20+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
21+
import org.junit.jupiter.api.Test;
22+
23+
import static org.assertj.core.api.Assertions.assertThat;
24+
import static org.junit.jupiter.api.Assertions.fail;
2125

22-
import static org.junit.Assert.assertEquals;
23-
import static org.junit.Assert.fail;
2426

2527
/**
2628
* @author Chris Cranford
2729
*/
2830
@JiraKey(value = "HHH-12320")
29-
public class ForeignKeyConstraintMapsIdTest extends BaseNonConfigCoreFunctionalTestCase {
31+
@DomainModel(
32+
annotatedClasses = {
33+
ForeignKeyConstraintMapsIdTest.Post.class,
34+
ForeignKeyConstraintMapsIdTest.PostDetails.class
35+
}
36+
)
37+
@SessionFactory
38+
public class ForeignKeyConstraintMapsIdTest {
39+
40+
@Test
41+
public void testForeignKeyNameSetForMapsIdJoinColumn(SessionFactoryScope scope) {
42+
MetadataImplementor metadata = scope.getMetadataImplementor();
43+
for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) {
44+
for ( Table table : namespace.getTables() ) {
45+
if ( table.getName().equals( "Post" ) ) {
46+
for ( var foreignKey : table.getForeignKeyCollection() ) {
47+
if ( foreignKey.getColumn( 0 ).getName().equals( "PD_ID" ) ) {
48+
assertThat( foreignKey.getName() ).isEqualTo( "FK_PD" );
49+
return;
50+
}
51+
}
52+
}
53+
}
54+
}
55+
fail( "Expected to find a Foreign Key mapped to column PD_ID but failed to locate it" );
56+
}
57+
3058
@Entity(name = "Post")
3159
public static class Post {
3260
@Id
@@ -76,26 +104,4 @@ public void setUserName(String userName) {
76104
this.userName = userName;
77105
}
78106
}
79-
80-
@Override
81-
protected Class<?>[] getAnnotatedClasses() {
82-
return new Class<?>[] { Post.class, PostDetails.class };
83-
}
84-
85-
@Test
86-
public void testForeignKeyNameSetForMapsIdJoinColumn() {
87-
for ( Namespace namespace : metadata().getDatabase().getNamespaces() ) {
88-
for ( Table table : namespace.getTables() ) {
89-
if ( table.getName().equals( "Post" ) ) {
90-
for ( var foreignKey : table.getForeignKeyCollection() ) {
91-
if ( foreignKey.getColumn( 0 ).getName().equals( "PD_ID" ) ) {
92-
assertEquals( "FK_PD", foreignKey.getName() );
93-
return;
94-
}
95-
}
96-
}
97-
}
98-
}
99-
fail( "Expected to find a Foreign Key mapped to column PD_ID but failed to locate it" );
100-
}
101107
}

hibernate-core/src/test/java/org/hibernate/orm/test/constraint/ForeignKeyNoConstraintTest.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,49 @@
1313
import jakarta.persistence.MapsId;
1414
import jakarta.persistence.OneToOne;
1515
import jakarta.persistence.PrimaryKeyJoinColumn;
16-
1716
import org.hibernate.boot.model.relational.Namespace;
1817
import org.hibernate.mapping.Table;
19-
18+
import org.hibernate.testing.orm.junit.DomainModel;
2019
import org.hibernate.testing.orm.junit.JiraKey;
21-
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
22-
import org.junit.Test;
20+
import org.hibernate.testing.orm.junit.SessionFactory;
21+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
22+
import org.junit.jupiter.api.Test;
2323

24-
import static org.junit.Assert.assertEquals;
24+
import static org.assertj.core.api.Assertions.assertThat;
2525

2626
/**
2727
* @author Chris Cranford
2828
*/
29-
public class ForeignKeyNoConstraintTest extends BaseNonConfigCoreFunctionalTestCase {
30-
@Override
31-
protected Class[] getAnnotatedClasses() {
32-
return new Class<?>[] {
33-
Car.class,
34-
VehicleNumber.class,
35-
Post.class,
36-
PostDetails.class
37-
};
38-
}
29+
@DomainModel(
30+
annotatedClasses = {
31+
ForeignKeyNoConstraintTest.Car.class,
32+
ForeignKeyNoConstraintTest.VehicleNumber.class,
33+
ForeignKeyNoConstraintTest.Post.class,
34+
ForeignKeyNoConstraintTest.PostDetails.class
35+
}
36+
)
37+
@SessionFactory
38+
public class ForeignKeyNoConstraintTest {
3939

4040
@Test
4141
@JiraKey(value = "HHH-12975")
42-
public void testPrimaryKeyJoinColumnForeignKeyNoConstraint() {
43-
for ( Namespace namespace : metadata().getDatabase().getNamespaces() ) {
42+
public void testPrimaryKeyJoinColumnForeignKeyNoConstraint(SessionFactoryScope scope) {
43+
for ( Namespace namespace : scope.getMetadataImplementor().getDatabase().getNamespaces() ) {
4444
for ( Table table : namespace.getTables() ) {
4545
if ( "Car".equals( table.getName() ) ) {
46-
assertEquals( 0, table.getForeignKeyCollection().size() );
46+
assertThat( table.getForeignKeyCollection() ).hasSize( 0 );
4747
}
4848
}
4949
}
5050
}
5151

5252
@Test
5353
@JiraKey(value = "HHH-12975")
54-
public void testMapsIdJoinColumnForeignKeyNoConstraint() {
55-
for ( Namespace namespace : metadata().getDatabase().getNamespaces() ) {
54+
public void testMapsIdJoinColumnForeignKeyNoConstraint(SessionFactoryScope scope) {
55+
for ( Namespace namespace : scope.getMetadataImplementor().getDatabase().getNamespaces() ) {
5656
for ( Table table : namespace.getTables() ) {
5757
if ( "Post".equals( table.getName() ) ) {
58-
assertEquals( 0, table.getForeignKeyCollection().size() );
58+
assertThat( table.getForeignKeyCollection() ).hasSize( 0 );
5959
}
6060
}
6161
}
@@ -68,7 +68,7 @@ public static class Car {
6868

6969
@PrimaryKeyJoinColumn
7070
@OneToOne(optional = false)
71-
@JoinColumn(name = "V_ID", foreignKey = @ForeignKey( ConstraintMode.NO_CONSTRAINT ) )
71+
@JoinColumn(name = "V_ID", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
7272
private VehicleNumber vehicleNumber;
7373

7474
public Integer getId() {

0 commit comments

Comments
 (0)