|
4 | 4 | */ |
5 | 5 | package org.hibernate.orm.test.bytecode; |
6 | 6 |
|
7 | | -import java.text.ParseException; |
8 | | - |
9 | 7 | import org.hibernate.Hibernate; |
10 | | -import org.hibernate.Session; |
11 | | - |
12 | | -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; |
13 | | -import org.junit.Test; |
14 | | - |
15 | | -import static org.junit.Assert.assertFalse; |
16 | | -import static org.junit.Assert.fail; |
17 | | - |
18 | | -public class InvocationTargetExceptionTest extends BaseCoreFunctionalTestCase { |
| 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; |
19 | 13 |
|
20 | | - @Override |
21 | | - protected String getBaseForMappings() { |
22 | | - return "org/hibernate/orm/test/"; |
23 | | - } |
| 14 | +import java.text.ParseException; |
24 | 15 |
|
25 | | - @Override |
26 | | - public String[] getMappings() { |
27 | | - return new String[] { "bytecode/Bean.hbm.xml" }; |
28 | | - } |
| 16 | +import static org.assertj.core.api.Assertions.assertThat; |
| 17 | +import static org.junit.jupiter.api.Assertions.fail; |
29 | 18 |
|
| 19 | +@SuppressWarnings("JUnitMalformedDeclaration") |
| 20 | +@DomainModel(xmlMappings = "org/hibernate/orm/test/bytecode/Bean.xml") |
| 21 | +@SessionFactory |
| 22 | +public class InvocationTargetExceptionTest { |
30 | 23 | @Test |
31 | | - public void testProxiedInvocationException() { |
32 | | - Session s = openSession(); |
33 | | - s.beginTransaction(); |
34 | | - Bean bean = new Bean(); |
35 | | - bean.setSomeString( "my-bean" ); |
36 | | - s.persist( bean ); |
37 | | - s.getTransaction().commit(); |
38 | | - s.close(); |
39 | | - |
40 | | - s = openSession(); |
41 | | - s.beginTransaction(); |
42 | | - bean = ( Bean ) s.getReference( Bean.class, bean.getSomeString() ); |
43 | | - assertFalse( Hibernate.isInitialized( bean ) ); |
44 | | - try { |
45 | | - bean.throwException(); |
46 | | - fail( "exception not thrown" ); |
47 | | - } |
48 | | - catch ( ParseException e ) { |
49 | | - // expected behavior |
50 | | - } |
51 | | - catch ( Throwable t ) { |
52 | | - fail( "unexpected exception type : " + t ); |
53 | | - } |
| 24 | + public void testProxiedInvocationException(SessionFactoryScope factoryScope) { |
| 25 | + factoryScope.inTransaction( (s) -> { |
| 26 | + Bean bean = new Bean(); |
| 27 | + bean.setSomeString( "my-bean" ); |
| 28 | + s.persist( bean ); |
| 29 | + } ); |
| 30 | + |
| 31 | + factoryScope.inTransaction( (s) -> { |
| 32 | + Bean bean = s.getReference( Bean.class, "my-bean" ); |
| 33 | + assertThat( Hibernate.isInitialized( bean ) ).isFalse(); |
| 34 | + try { |
| 35 | + bean.throwException(); |
| 36 | + fail( "exception not thrown" ); |
| 37 | + } |
| 38 | + catch ( ParseException e ) { |
| 39 | + // expected behavior |
| 40 | + } |
| 41 | + catch ( Throwable t ) { |
| 42 | + fail( "unexpected exception type : " + t ); |
| 43 | + } |
| 44 | + } ); |
| 45 | + } |
54 | 46 |
|
55 | | - s.remove( bean ); |
56 | | - s.getTransaction().commit(); |
57 | | - s.close(); |
| 47 | + @AfterEach |
| 48 | + public void dropTestData(SessionFactoryScope factoryScope) throws Exception { |
| 49 | + factoryScope.dropData(); |
58 | 50 | } |
59 | 51 | } |
0 commit comments