Skip to content

Commit 1987e92

Browse files
committed
HHH-19324 - Switch tests using hbm.xml to use mapping.xml
1 parent 7b5b674 commit 1987e92

File tree

4 files changed

+38
-47
lines changed

4 files changed

+38
-47
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/bytecode/Hammer.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,30 @@
44
*/
55
package org.hibernate.orm.test.annotations.bytecode;
66

7+
import jakarta.persistence.Entity;
8+
import jakarta.persistence.GeneratedValue;
9+
import jakarta.persistence.Id;
710

811
/**
912
* @author Emmanuel Bernard
1013
*/
14+
@Entity
1115
public class Hammer implements Tool {
1216
private Long id;
1317

18+
@Id
19+
@GeneratedValue(generator = "increment")
20+
@Override
1421
public Long getId() {
1522
return id;
1623
}
1724

25+
@Override
1826
public void setId(Long id) {
1927
this.id = id;
2028
}
2129

30+
@Override
2231
public Integer usage() {
2332
return 0;
2433
}

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/bytecode/ProxyBreakingTest.java

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,39 @@
55
package org.hibernate.orm.test.annotations.bytecode;
66

77
import org.hibernate.Hibernate;
8-
import org.hibernate.Session;
9-
import org.hibernate.Transaction;
8+
import org.hibernate.testing.orm.junit.DomainModel;
9+
import org.hibernate.testing.orm.junit.SessionFactory;
10+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
11+
import org.junit.jupiter.api.AfterEach;
12+
import org.junit.jupiter.api.Test;
1013

11-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
12-
import org.junit.Test;
13-
14-
import static org.junit.Assert.assertFalse;
15-
import static org.junit.Assert.assertNotNull;
14+
import static org.assertj.core.api.Assertions.assertThat;
1615

1716
/**
1817
* @author Emmanuel Bernard
1918
*/
20-
public class ProxyBreakingTest extends BaseCoreFunctionalTestCase {
19+
@SuppressWarnings("JUnitMalformedDeclaration")
20+
@DomainModel(annotatedClasses = {Tool.class, Hammer.class})
21+
@SessionFactory
22+
public class ProxyBreakingTest {
2123
@Test
22-
public void testProxiedBridgeMethod() throws Exception {
23-
//bridge methods should not be proxied
24-
Session s = openSession();
25-
Transaction tx = s.beginTransaction();
26-
Hammer h = new Hammer();
27-
s.persist(h);
28-
s.flush();
29-
s.clear();
30-
assertNotNull( "The proxy creation failure is breaking things", h.getId() );
31-
h = (Hammer) s.getReference( Hammer.class, h.getId() );
32-
assertFalse( Hibernate.isInitialized( h ) );
33-
tx.rollback();
34-
s.close();
24+
public void testProxiedBridgeMethod(SessionFactoryScope factoryScope) {
25+
final Hammer persisted = factoryScope.fromTransaction( (session) -> {
26+
final Hammer hammer = new Hammer();
27+
session.persist( hammer );
28+
return hammer;
29+
} );
30+
31+
assertThat( persisted.getId() ).isNotNull();
32+
33+
factoryScope.inTransaction( (session) -> {
34+
final Hammer reference = session.getReference( Hammer.class, persisted.getId() );
35+
assertThat( Hibernate.isInitialized( reference ) ).isFalse();
36+
} );
3537
}
3638

37-
@Override
38-
protected String[] getOrmXmlFiles() {
39-
return new String[] {
40-
"org/hibernate/orm/test/annotations/bytecode/Hammer.hbm.xml"
41-
};
39+
@AfterEach
40+
void dropTestData(SessionFactoryScope factoryScope) {
41+
factoryScope.dropData();
4242
}
4343
}

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/bytecode/Tool.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
*/
55
package org.hibernate.orm.test.annotations.bytecode;
66

7-
87
/**
98
* @author Emmanuel Bernard
109
*/
1110
public interface Tool {
12-
public Long getId();
13-
14-
public void setId(Long id);
11+
Long getId();
12+
void setId(Long id);
1513

16-
public Number usage();
14+
Number usage();
1715
}

hibernate-core/src/test/resources/org/hibernate/orm/test/annotations/bytecode/Hammer.hbm.xml

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)