Skip to content

Commit f5e7297

Browse files
dreab8sebersole
authored andcommitted
HHH-19916 More drop JUnit 4 usage work
1 parent 3dada25 commit f5e7297

33 files changed

+915
-825
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/entitynonentity/EntityNonEntityTest.java

Lines changed: 78 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -4,104 +4,98 @@
44
*/
55
package org.hibernate.orm.test.annotations.entitynonentity;
66

7-
import org.hibernate.Session;
8-
import org.hibernate.Transaction;
97
import org.hibernate.UnknownEntityTypeException;
10-
8+
import org.hibernate.testing.orm.junit.DomainModel;
119
import org.hibernate.testing.orm.junit.JiraKey;
12-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
13-
import org.junit.Test;
10+
import org.hibernate.testing.orm.junit.SessionFactory;
11+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
12+
import org.junit.jupiter.api.AfterEach;
13+
import org.junit.jupiter.api.Test;
1414

15-
import static org.junit.Assert.assertEquals;
16-
import static org.junit.Assert.assertNull;
17-
import static org.junit.Assert.assertTrue;
18-
import static org.junit.Assert.fail;
15+
import static org.assertj.core.api.Assertions.assertThat;
16+
import static org.junit.jupiter.api.Assertions.assertThrows;
1917

2018
/**
2119
* @author Emmanuel Bernard
2220
*/
23-
public class EntityNonEntityTest extends BaseCoreFunctionalTestCase {
24-
@Test
25-
public void testMix() {
26-
GSM gsm = new GSM();
27-
gsm.brand = "Sony";
28-
gsm.frequency = 900;
29-
gsm.isNumeric = true;
30-
gsm.number = 2;
31-
gsm.species = "human";
32-
Session s = openSession();
33-
Transaction tx = s.beginTransaction();
34-
s.persist( gsm );
35-
tx.commit();
36-
s.clear();
37-
tx = s.beginTransaction();
38-
gsm = s.get( GSM.class, gsm.id );
39-
assertEquals( "top mapped superclass", 2, gsm.number );
40-
assertNull( "non entity between mapped superclass and entity", gsm.species );
41-
assertTrue( "mapped superclass under entity", gsm.isNumeric );
42-
assertNull( "non entity under entity", gsm.brand );
43-
assertEquals( "leaf entity", 900, gsm.frequency );
44-
s.remove( gsm );
45-
tx.commit();
46-
s.close();
21+
@DomainModel(
22+
annotatedClasses = {
23+
Phone.class,
24+
Voice.class,
25+
// Adding Cellular here is a test for HHH-9855
26+
Cellular.class,
27+
GSM.class
28+
}
29+
)
30+
@SessionFactory
31+
public class EntityNonEntityTest {
32+
33+
@AfterEach
34+
public void tearDown(SessionFactoryScope scope) {
35+
scope.inTransaction(
36+
session ->
37+
scope.getSessionFactory().getSchemaManager().truncateMappedObjects()
38+
);
4739
}
4840

4941
@Test
50-
@JiraKey( value = "HHH-9856" )
51-
public void testGetAndFindNonEntityThrowsIllegalArgumentException() {
52-
try {
53-
sessionFactory().getMappingMetamodel().findEntityDescriptor(Cellular.class);
54-
sessionFactory().getMappingMetamodel().getEntityDescriptor( Cellular.class );
42+
public void testMix(SessionFactoryScope scope) {
43+
scope.inTransaction(
44+
session -> {
45+
GSM gsm = new GSM();
46+
gsm.brand = "Sony";
47+
gsm.frequency = 900;
48+
gsm.isNumeric = true;
49+
gsm.number = 2;
50+
gsm.species = "human";
51+
session.persist( gsm );
52+
session.getTransaction().commit();
53+
session.clear();
54+
session.beginTransaction();
55+
gsm = session.get( GSM.class, gsm.id );
5556

56-
}
57-
catch (UnknownEntityTypeException ignore) {
58-
// expected
59-
}
57+
assertThat( gsm.number )
58+
.describedAs( "top mapped superclass" )
59+
.isEqualTo( 2 );
60+
assertThat( gsm.species )
61+
.describedAs( "non entity between mapped superclass and entity" )
62+
.isNull();
63+
assertThat( gsm.isNumeric )
64+
.describedAs( "mapped superclass under entity" )
65+
.isTrue();
66+
assertThat( gsm.brand )
67+
.describedAs( "non entity under entity" )
68+
.isNull();
69+
assertThat( gsm.frequency )
70+
.describedAs( "leaf entity" )
71+
.isEqualTo( 900 );
6072

61-
try {
62-
sessionFactory().getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor( Cellular.class.getName() );
63-
}
64-
catch (UnknownEntityTypeException ignore) {
65-
// expected
66-
}
73+
session.remove( gsm );
74+
}
75+
);
76+
}
6777

68-
Session s = openSession();
69-
s.beginTransaction();
70-
try {
71-
s.get( Cellular.class, 1 );
72-
fail( "Expecting a failure" );
73-
}
74-
catch (UnknownEntityTypeException ignore) {
75-
// expected
76-
}
77-
finally {
78-
s.getTransaction().commit();
79-
s.close();
80-
}
78+
@Test
79+
@JiraKey(value = "HHH-9856")
80+
public void testGetAndFindNonEntityThrowsIllegalArgumentException(SessionFactoryScope scope) {
81+
assertThrows( UnknownEntityTypeException.class, () -> {
82+
scope.getSessionFactory().getMappingMetamodel().findEntityDescriptor( Cellular.class );
83+
scope.getSessionFactory().getMappingMetamodel().getEntityDescriptor( Cellular.class );
84+
} );
8185

82-
s = openSession();
83-
s.beginTransaction();
84-
try {
85-
s.get( Cellular.class.getName(), 1 );
86-
fail( "Expecting a failure" );
87-
}
88-
catch (UnknownEntityTypeException ignore) {
89-
// expected
90-
}
91-
finally {
92-
s.getTransaction().commit();
93-
s.close();
94-
}
95-
}
86+
assertThrows( UnknownEntityTypeException.class, () ->
87+
scope.getSessionFactory().getMappingMetamodel().getMappingMetamodel()
88+
.getEntityDescriptor( Cellular.class.getName() )
89+
);
9690

97-
@Override
98-
protected Class[] getAnnotatedClasses() {
99-
return new Class[]{
100-
Phone.class,
101-
Voice.class,
102-
// Adding Cellular here is a test for HHH-9855
103-
Cellular.class,
104-
GSM.class
105-
};
91+
assertThrows( UnknownEntityTypeException.class, () -> scope.inTransaction(
92+
session ->
93+
session.get( Cellular.class, 1 )
94+
) );
95+
96+
assertThrows( UnknownEntityTypeException.class, () -> scope.inTransaction(
97+
session ->
98+
session.get( Cellular.class.getName(), 1 )
99+
) );
106100
}
107101
}

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/entitynonentity/GSM.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.entitynonentity;
6+
67
import jakarta.persistence.Entity;
78

89
/**

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/entitynonentity/Phone.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.entitynonentity;
6+
67
import jakarta.persistence.MappedSuperclass;
78

89
/**

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/entitynonentity/Voice.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.entitynonentity;
6+
67
import jakarta.persistence.Entity;
78
import jakarta.persistence.GeneratedValue;
89
import jakarta.persistence.Id;

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/onetomany/A.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class A {
3232
@OneToMany( cascade = CascadeType.ALL)
3333
@Cascade(org.hibernate.annotations.CascadeType.ALL)
3434
@OrderBy("name")
35-
java.util.List<B> bs = new ArrayList<B>();
35+
java.util.List<B> bs = new ArrayList<>();
3636

3737

3838

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/onetomany/B.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class B {
3333
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
3434
@Cascade(org.hibernate.annotations.CascadeType.ALL)
3535
@OrderBy("name")
36-
java.util.List<C> cs = new ArrayList<C>();
36+
java.util.List<C> cs = new ArrayList<>();
3737

3838
public Long getId() {
3939
return id;

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/onetomany/BankAccount.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void setTransactions(List<Transaction> transactions) {
4646

4747
public void addTransaction(String code) {
4848
if ( transactions == null ) {
49-
transactions = new ArrayList<Transaction>();
49+
transactions = new ArrayList<>();
5050
}
5151
Transaction transaction = new Transaction();
5252
transaction.setCode( code );

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/onetomany/Box.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class Box implements Serializable {
2222

2323
@OneToMany( mappedBy = "box" )
2424
@OrderBy( "sortField DESC, code" ) // Sorting by @Formula calculated field.
25-
private List<Item> items = new ArrayList<Item>();
25+
private List<Item> items = new ArrayList<>();
2626

2727
public Box() {
2828
}

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/onetomany/Comment.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
import jakarta.persistence.JoinColumn;
1919
import jakarta.persistence.ManyToOne;
2020

21-
@Entity(name="CommentTable") // "Comment" reserved in Oracle
21+
@Entity(name = "CommentTable") // "Comment" reserved in Oracle
2222
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
23-
@DiscriminatorColumn(name = "DTYPE", discriminatorType= DiscriminatorType.STRING, length = 3)
23+
@DiscriminatorColumn(name = "DTYPE", discriminatorType = DiscriminatorType.STRING, length = 3)
2424
@DiscriminatorValue(value = "WPT")
2525
public class Comment {
2626

@@ -40,8 +40,8 @@ public void setId(Long id) {
4040
this.id = id;
4141
}
4242

43-
@ManyToOne(optional=true,fetch=FetchType.LAZY)
44-
@JoinColumn(name="FK_PostId", nullable=true, insertable=true,updatable=false)
43+
@ManyToOne(fetch = FetchType.LAZY)
44+
@JoinColumn(name = "FK_PostId", updatable = false)
4545
public Post getPost() {
4646
return post;
4747
}
@@ -50,8 +50,8 @@ public void setPost(Post family) {
5050
this.post = family;
5151
}
5252

53-
@ManyToOne(optional=true,fetch=FetchType.LAZY)
54-
@JoinColumn(name="FK_ForumId", nullable=true, insertable=true,updatable=false)
53+
@ManyToOne(fetch = FetchType.LAZY)
54+
@JoinColumn(name = "FK_ForumId", updatable = false)
5555
public Forum getForum() {
5656
return forum;
5757
}

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/onetomany/Employee.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class Employee {
1313

1414
@OneToMany(cascade = CascadeType.ALL, mappedBy = "employee", orphanRemoval = true)
1515
@OrderBy // order by PK
16-
private final List<Asset> assets = new ArrayList<Asset>();
16+
private final List<Asset> assets = new ArrayList<>();
1717

1818
@Id
1919
@Column(name = "id")

0 commit comments

Comments
 (0)