Skip to content

Commit 08fc1fd

Browse files
committed
HHH-19846 Drop JUnit 4 usage
1 parent 6b27991 commit 08fc1fd

23 files changed

+1389
-1419
lines changed

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

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

77
import org.hibernate.orm.test.sql.hand.custom.CustomStoredProcTestSupport;
8-
8+
import org.hibernate.testing.orm.junit.DomainModel;
99
import org.hibernate.testing.orm.junit.RequiresDialect;
1010

1111

1212
/**
1313
* @author Andrea Boriero
1414
*/
1515
@RequiresDialect(DerbyDialect.class)
16+
@DomainModel(
17+
xmlMappings = "org/hibernate/orm/test/derby/Mappings.hbm.xml"
18+
)
1619
public class DerbyCustomSQLTest extends CustomStoredProcTestSupport {
17-
public String[] getMappings() {
18-
return new String[] {"derby/Mappings.hbm.xml"};
19-
}
2020
}

hibernate-core/src/test/java/org/hibernate/orm/test/bulkid/AbstractMutationStrategyGeneratedIdWithOptimizerTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import jakarta.persistence.Entity;
88
import jakarta.persistence.GeneratedValue;
9-
import jakarta.persistence.GenerationType;
109
import jakarta.persistence.Id;
1110
import jakarta.persistence.Inheritance;
1211
import jakarta.persistence.InheritanceType;

hibernate-core/src/test/java/org/hibernate/orm/test/sorted/map/SortComparatorTest.java

Lines changed: 54 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
*/
55
package org.hibernate.orm.test.sorted.map;
66

7-
import java.util.Iterator;
8-
import java.util.Map;
9-
import java.util.SortedMap;
10-
import java.util.TreeMap;
117
import jakarta.persistence.CascadeType;
128
import jakarta.persistence.Entity;
139
import jakarta.persistence.GeneratedValue;
@@ -16,68 +12,71 @@
1612
import jakarta.persistence.MapKey;
1713
import jakarta.persistence.OneToMany;
1814
import jakarta.persistence.Table;
19-
20-
import org.hibernate.Session;
2115
import org.hibernate.annotations.SortComparator;
2216
import org.hibernate.orm.test.sorted.StringCaseInsensitiveComparator;
17+
import org.hibernate.testing.orm.junit.DomainModel;
18+
import org.hibernate.testing.orm.junit.SessionFactory;
19+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
20+
import org.junit.jupiter.api.Test;
2321

24-
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
25-
import org.junit.Test;
22+
import java.util.Iterator;
23+
import java.util.Map;
24+
import java.util.SortedMap;
25+
import java.util.TreeMap;
2626

27-
import static org.junit.Assert.assertEquals;
28-
import static org.junit.Assert.assertNotNull;
27+
import static org.assertj.core.api.Assertions.assertThat;
2928

30-
@SuppressWarnings( "unused" )
31-
public class SortComparatorTest extends BaseNonConfigCoreFunctionalTestCase {
3229

33-
@Override
34-
protected Class<?>[] getAnnotatedClasses() {
35-
return new Class<?>[] { Owner.class, Cat.class };
36-
}
30+
@DomainModel(
31+
annotatedClasses = {
32+
SortComparatorTest.Owner.class,
33+
SortComparatorTest.Cat.class
34+
}
35+
)
36+
@SessionFactory
37+
public class SortComparatorTest {
3738

3839
@Test
39-
public void testSortComparator() {
40-
Session s = openSession();
41-
s.beginTransaction();
42-
43-
Owner owner = new Owner();
44-
Cat cat1 = new Cat();
45-
Cat cat2 = new Cat();
46-
cat1.owner = owner;
47-
cat1.name = "B";
48-
cat1.nickname = "B";
49-
cat2.owner = owner;
50-
cat2.name = "a";
51-
cat2.nickname = "a";
52-
owner.cats.put( cat1.nickname, cat1 );
53-
owner.cats.put( cat2.nickname, cat2 );
54-
s.persist( owner );
55-
56-
s.getTransaction().commit();
57-
s.clear();
58-
59-
s.beginTransaction();
60-
61-
owner = s.get( Owner.class, owner.id );
62-
assertNotNull( owner.cats );
63-
assertEquals( 2, owner.cats.size() );
64-
65-
Iterator<Map.Entry<String, Cat>> entryIterator = owner.cats.entrySet().iterator();
66-
Map.Entry<String, Cat> firstEntry = entryIterator.next();
67-
Map.Entry<String, Cat> secondEntry = entryIterator.next();
68-
69-
assertEquals( "a", firstEntry.getKey() );
70-
assertEquals( "a", firstEntry.getValue().nickname );
71-
assertEquals( "B", secondEntry.getKey() );
72-
assertEquals( "B", secondEntry.getValue().nickname );
73-
74-
s.getTransaction().commit();
75-
s.close();
40+
public void testSortComparator(SessionFactoryScope scope) {
41+
scope.inTransaction(
42+
session -> {
43+
Owner owner = new Owner();
44+
Cat cat1 = new Cat();
45+
Cat cat2 = new Cat();
46+
cat1.owner = owner;
47+
cat1.name = "B";
48+
cat1.nickname = "B";
49+
cat2.owner = owner;
50+
cat2.name = "a";
51+
cat2.nickname = "a";
52+
owner.cats.put( cat1.nickname, cat1 );
53+
owner.cats.put( cat2.nickname, cat2 );
54+
session.persist( owner );
55+
56+
session.getTransaction().commit();
57+
session.clear();
58+
59+
session.beginTransaction();
60+
61+
owner = session.get( Owner.class, owner.id );
62+
assertThat( owner.cats ).isNotNull();
63+
assertThat( owner.cats.size()).isEqualTo(2);
64+
65+
Iterator<Map.Entry<String, Cat>> entryIterator = owner.cats.entrySet().iterator();
66+
Map.Entry<String, Cat> firstEntry = entryIterator.next();
67+
Map.Entry<String, Cat> secondEntry = entryIterator.next();
68+
69+
assertThat( firstEntry.getKey()).isEqualTo("a");
70+
assertThat( firstEntry.getValue().nickname).isEqualTo("a");
71+
assertThat( secondEntry.getKey()).isEqualTo("B");
72+
assertThat( secondEntry.getValue().nickname).isEqualTo("B");
73+
}
74+
);
7675
}
7776

7877
@Entity(name = "Owner")
7978
@Table(name = "Owner")
80-
private static class Owner {
79+
static class Owner {
8180

8281
@Id
8382
@GeneratedValue
@@ -91,7 +90,7 @@ private static class Owner {
9190

9291
@Entity(name = "Cat")
9392
@Table(name = "Cat")
94-
private static class Cat implements Comparable<Cat> {
93+
static class Cat implements Comparable<Cat> {
9594

9695
@Id
9796
@GeneratedValue

hibernate-core/src/test/java/org/hibernate/orm/test/sorted/map/SortNaturalTest.java

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
*/
55
package org.hibernate.orm.test.sorted.map;
66

7-
import java.util.Iterator;
8-
import java.util.Map;
9-
import java.util.SortedMap;
10-
import java.util.TreeMap;
117
import jakarta.persistence.CascadeType;
128
import jakarta.persistence.Entity;
139
import jakarta.persistence.GeneratedValue;
@@ -16,65 +12,68 @@
1612
import jakarta.persistence.MapKey;
1713
import jakarta.persistence.OneToMany;
1814
import jakarta.persistence.Table;
19-
20-
import org.hibernate.Session;
2115
import org.hibernate.annotations.SortNatural;
16+
import org.hibernate.testing.orm.junit.DomainModel;
17+
import org.hibernate.testing.orm.junit.SessionFactory;
18+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
19+
import org.junit.jupiter.api.Test;
2220

23-
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
24-
import org.junit.Test;
21+
import java.util.Iterator;
22+
import java.util.Map;
23+
import java.util.SortedMap;
24+
import java.util.TreeMap;
2525

26-
import static org.junit.Assert.assertEquals;
27-
import static org.junit.Assert.assertNotNull;
26+
import static org.assertj.core.api.Assertions.assertThat;
2827

2928
@SuppressWarnings( "unused" )
30-
public class SortNaturalTest extends BaseNonConfigCoreFunctionalTestCase {
31-
32-
@Override
33-
protected Class<?>[] getAnnotatedClasses() {
34-
return new Class<?>[] { Owner.class, Cat.class };
35-
}
29+
@DomainModel(
30+
annotatedClasses = {
31+
SortNaturalTest.Owner.class,
32+
SortNaturalTest.Cat.class
33+
}
34+
)
35+
@SessionFactory
36+
public class SortNaturalTest {
3637

3738
@Test
38-
public void testSortNatural() {
39-
Session s = openSession();
40-
s.beginTransaction();
41-
42-
Owner owner = new Owner();
43-
Cat cat1 = new Cat();
44-
Cat cat2 = new Cat();
45-
cat1.owner = owner;
46-
cat1.name = "B";
47-
cat2.owner = owner;
48-
cat2.name = "A";
49-
owner.cats.put( cat1.name, cat1 );
50-
owner.cats.put( cat2.name, cat2 );
51-
s.persist( owner );
52-
53-
s.getTransaction().commit();
54-
s.clear();
55-
56-
s.beginTransaction();
57-
58-
owner = s.get( Owner.class, owner.id );
59-
assertNotNull(owner.cats);
60-
assertEquals( 2, owner.cats.size() );
61-
62-
Iterator<Map.Entry<String, Cat>> entryIterator = owner.cats.entrySet().iterator();
63-
Map.Entry<String, Cat> firstEntry = entryIterator.next();
64-
Map.Entry<String, Cat> secondEntry = entryIterator.next();
65-
66-
assertEquals( "A", firstEntry.getKey() );
67-
assertEquals( "A", firstEntry.getValue().name );
68-
assertEquals( "B", secondEntry.getKey() );
69-
assertEquals( "B", secondEntry.getValue().name );
70-
71-
s.getTransaction().commit();
72-
s.close();
39+
public void testSortNatural(SessionFactoryScope scope) {
40+
scope.inTransaction(
41+
session -> {
42+
Owner owner = new Owner();
43+
Cat cat1 = new Cat();
44+
Cat cat2 = new Cat();
45+
cat1.owner = owner;
46+
cat1.name = "B";
47+
cat2.owner = owner;
48+
cat2.name = "A";
49+
owner.cats.put( cat1.name, cat1 );
50+
owner.cats.put( cat2.name, cat2 );
51+
session.persist( owner );
52+
53+
session.getTransaction().commit();
54+
session.clear();
55+
56+
session.beginTransaction();
57+
58+
owner = session.get( Owner.class, owner.id );
59+
assertThat( owner.cats ).isNotNull();
60+
assertThat( owner.cats.size()).isEqualTo(2);
61+
62+
Iterator<Map.Entry<String, Cat>> entryIterator = owner.cats.entrySet().iterator();
63+
Map.Entry<String, Cat> firstEntry = entryIterator.next();
64+
Map.Entry<String, Cat> secondEntry = entryIterator.next();
65+
66+
assertThat( firstEntry.getKey()).isEqualTo("A");
67+
assertThat( firstEntry.getValue().name).isEqualTo("A");
68+
assertThat( secondEntry.getKey()).isEqualTo("B");
69+
assertThat( secondEntry.getValue().name).isEqualTo("B");
70+
}
71+
);
7372
}
7473

7574
@Entity(name = "Owner")
7675
@Table(name = "Owner")
77-
private static class Owner {
76+
static class Owner {
7877

7978
@Id
8079
@GeneratedValue
@@ -88,7 +87,7 @@ private static class Owner {
8887

8988
@Entity(name = "Cat")
9089
@Table(name = "Cat")
91-
private static class Cat implements Comparable<Cat> {
90+
static class Cat implements Comparable<Cat> {
9291

9392
@Id
9493
@GeneratedValue

0 commit comments

Comments
 (0)