Skip to content

Commit 85f12d6

Browse files
committed
HHH-19846 Drop JUnit 4 usage
1 parent f95e007 commit 85f12d6

File tree

5 files changed

+177
-165
lines changed

5 files changed

+177
-165
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/indexcoll/GenerationGroup.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.indexcoll;
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/indexcoll/GenerationUser.java

Lines changed: 2 additions & 1 deletion
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.indexcoll;
6+
67
import java.util.HashMap;
78
import java.util.Map;
89
import jakarta.persistence.Entity;
@@ -23,7 +24,7 @@ public class GenerationUser {
2324

2425
@OneToMany
2526
@MapKey(name="generation")
26-
private Map<Generation, GenerationGroup> ref = new HashMap<Generation, GenerationGroup>();
27+
private Map<Generation, GenerationGroup> ref = new HashMap<>();
2728

2829
public int getId() {
2930
return id;

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/indexcoll/MapKeyTest.java

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,47 @@
44
*/
55
package org.hibernate.orm.test.annotations.indexcoll;
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-
13-
import static org.junit.Assert.assertEquals;
12+
import static org.assertj.core.api.Assertions.assertThat;
1413

1514
/**
1615
* @author Emmanuel Bernard
1716
*/
18-
public class MapKeyTest extends BaseCoreFunctionalTestCase {
19-
@Test
20-
public void testMapKeyOnEmbeddedId() {
21-
Session s = openSession();
22-
Transaction tx = s.beginTransaction();
23-
Generation c = new Generation();
24-
c.setAge( "a" );
25-
c.setCulture( "b" );
26-
c.setSubGeneration( new Generation.SubGeneration( "description" ) );
27-
GenerationGroup r = new GenerationGroup();
28-
r.setGeneration( c );
29-
s.persist( r );
30-
GenerationUser m = new GenerationUser();
31-
s.persist( m );
32-
m.getRef().put( c, r );
33-
s.flush();
34-
s.clear();
35-
36-
m = (GenerationUser) s.get( GenerationUser.class, m.getId() );
37-
Generation cRead = m.getRef().keySet().iterator().next();
38-
assertEquals( "a",cRead.getAge() );
39-
assertEquals( "description", cRead.getSubGeneration().getDescription() );
40-
tx.rollback();
41-
s.close();
42-
}
43-
44-
@Override
45-
protected Class[] getAnnotatedClasses() {
46-
return new Class[] {
17+
@DomainModel(
18+
annotatedClasses = {
4719
GenerationUser.class,
4820
GenerationGroup.class
49-
};
21+
}
22+
)
23+
@SessionFactory
24+
public class MapKeyTest {
25+
26+
@Test
27+
public void testMapKeyOnEmbeddedId(SessionFactoryScope scope) {
28+
scope.inTransaction(
29+
session -> {
30+
Generation c = new Generation();
31+
c.setAge( "a" );
32+
c.setCulture( "b" );
33+
c.setSubGeneration( new Generation.SubGeneration( "description" ) );
34+
GenerationGroup r = new GenerationGroup();
35+
r.setGeneration( c );
36+
session.persist( r );
37+
GenerationUser m = new GenerationUser();
38+
session.persist( m );
39+
m.getRef().put( c, r );
40+
session.flush();
41+
session.clear();
42+
43+
m = session.find( GenerationUser.class, m.getId() );
44+
Generation cRead = m.getRef().keySet().iterator().next();
45+
assertThat( cRead.getAge() ).isEqualTo( "a" );
46+
assertThat( cRead.getSubGeneration().getDescription() ).isEqualTo( "description" );
47+
}
48+
);
5049
}
5150
}

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/indexcoll/eager/Atmosphere.java

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
* Copyright Red Hat Inc. and Hibernate Authors
44
*/
55
package org.hibernate.orm.test.annotations.indexcoll.eager;
6-
import java.util.Date;
7-
import java.util.HashMap;
8-
import java.util.Map;
6+
97
import jakarta.persistence.CascadeType;
108
import jakarta.persistence.Column;
119
import jakarta.persistence.ElementCollection;
@@ -23,17 +21,20 @@
2321
import jakarta.persistence.MapKeyJoinColumns;
2422
import jakarta.persistence.MapKeyTemporal;
2523
import jakarta.persistence.TemporalType;
26-
2724
import org.hibernate.orm.test.annotations.indexcoll.Gas;
2825
import org.hibernate.orm.test.annotations.indexcoll.GasKey;
2926

27+
import java.util.Date;
28+
import java.util.HashMap;
29+
import java.util.Map;
30+
3031
/**
3132
* @author Emmanuel Bernard
3233
*/
3334
@Entity
3435
public class Atmosphere {
3536

36-
public static enum Level {
37+
public enum Level {
3738
LOW,
3839
HIGH
3940
}
@@ -43,45 +44,45 @@ public static enum Level {
4344
public Integer id;
4445

4546
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
46-
@MapKeyColumn(name="gas_name")
47-
public Map<String, Gas> gases = new HashMap<String, Gas>();
47+
@MapKeyColumn(name = "gas_name")
48+
public Map<String, Gas> gases = new HashMap<>();
4849

4950
@MapKeyTemporal(TemporalType.DATE)
5051
@ElementCollection(fetch = FetchType.EAGER)
51-
@MapKeyColumn(nullable=false)
52-
public Map<Date, String> colorPerDate = new HashMap<Date,String>();
52+
@MapKeyColumn(nullable = false)
53+
public Map<Date, String> colorPerDate = new HashMap<>();
5354

5455
@ElementCollection(fetch = FetchType.EAGER)
5556
@MapKeyEnumerated(EnumType.STRING)
56-
@MapKeyColumn(nullable=false)
57-
public Map<Level, String> colorPerLevel = new HashMap<Level,String>();
57+
@MapKeyColumn(nullable = false)
58+
public Map<Level, String> colorPerLevel = new HashMap<>();
5859

5960
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
60-
@MapKeyJoinColumn(name="gas_id" )
61+
@MapKeyJoinColumn(name = "gas_id")
6162
@JoinTable(name = "Gas_per_key")
6263
public Map<GasKey, Gas> gasesPerKey = new HashMap<GasKey, Gas>();
6364

6465
@ElementCollection(fetch = FetchType.EAGER)
65-
@Column(name="composition_rate")
66-
@MapKeyJoinColumns( { @MapKeyJoinColumn(name="gas_id" ) } ) //use @MapKeyJoinColumns explicitly for tests
66+
@Column(name = "composition_rate")
67+
@MapKeyJoinColumns({@MapKeyJoinColumn(name = "gas_id")}) //use @MapKeyJoinColumns explicitly for tests
6768
@JoinTable(name = "Composition", joinColumns = @JoinColumn(name = "atmosphere_id"))
68-
public Map<Gas, Double> composition = new HashMap<Gas, Double>();
69+
public Map<Gas, Double> composition = new HashMap<>();
6970

7071
//use default JPA 2 column name for map key
7172
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
7273
@MapKeyColumn
73-
@JoinTable(name="Atm_Gas_Def")
74-
public Map<String, Gas> gasesDef = new HashMap<String, Gas>();
74+
@JoinTable(name = "Atm_Gas_Def")
75+
public Map<String, Gas> gasesDef = new HashMap<>();
7576

7677
//use default HAN legacy column name for map key
7778
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
7879
@MapKeyColumn
79-
@JoinTable(name="Atm_Gas_DefLeg")
80-
public Map<String, Gas> gasesDefLeg = new HashMap<String, Gas>();
80+
@JoinTable(name = "Atm_Gas_DefLeg")
81+
public Map<String, Gas> gasesDefLeg = new HashMap<>();
8182

8283
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
8384
@MapKeyJoinColumn
8485
@JoinTable(name = "Gas_p_key_def")
85-
public Map<GasKey, Gas> gasesPerKeyDef = new HashMap<GasKey, Gas>();
86+
public Map<GasKey, Gas> gasesPerKeyDef = new HashMap<>();
8687

8788
}

0 commit comments

Comments
 (0)