|
1 | 1 | package org.springframework.data.jpa.provider;
|
2 | 2 |
|
3 | 3 | import jakarta.persistence.EntityManager;
|
| 4 | + |
| 5 | +import java.lang.reflect.Method; |
| 6 | + |
4 | 7 | import org.junit.jupiter.api.Assertions;
|
5 | 8 | import org.junit.jupiter.api.Test;
|
6 | 9 | import org.junit.jupiter.api.extension.ExtendWith;
|
|
12 | 15 | import org.springframework.transaction.TransactionStatus;
|
13 | 16 | import org.springframework.transaction.support.DefaultTransactionDefinition;
|
14 | 17 |
|
15 |
| -import java.lang.reflect.Method; |
16 |
| - |
| 18 | +/** |
| 19 | + * Unit tests for {@link HibernateJpaParametersParameterAccessor}. |
| 20 | + * |
| 21 | + * @author Cedomir Igaly |
| 22 | + */ |
17 | 23 | @ExtendWith(SpringExtension.class)
|
18 | 24 | @ContextConfiguration("classpath:hjppa-test.xml")
|
19 | 25 | public class HibernateJpaParametersParameterAccessorUnitTests {
|
20 | 26 |
|
21 |
| - @Autowired |
22 |
| - private EntityManager em; |
| 27 | + @Autowired private EntityManager em; |
23 | 28 |
|
24 |
| - @Autowired |
25 |
| - private PlatformTransactionManager transactionManager; |
| 29 | + @Autowired private PlatformTransactionManager transactionManager; |
26 | 30 |
|
27 | 31 | @Test
|
28 | 32 | void withoutTransaction() throws NoSuchMethodException {
|
29 |
| - simpleTest(); |
| 33 | + parametersCanGetAccessesOutsideTransaction(); |
30 | 34 | }
|
31 | 35 |
|
32 | 36 | @Test
|
33 | 37 | void withinTransaction() throws Exception {
|
34 |
| - final TransactionStatus tx = transactionManager.getTransaction(new DefaultTransactionDefinition()); |
| 38 | + |
| 39 | + TransactionStatus tx = transactionManager.getTransaction(new DefaultTransactionDefinition()); |
35 | 40 | try {
|
36 |
| - simpleTest(); |
| 41 | + parametersCanGetAccessesOutsideTransaction(); |
37 | 42 | } finally {
|
38 | 43 | transactionManager.rollback(tx);
|
39 | 44 | }
|
40 | 45 | }
|
41 | 46 |
|
42 |
| - private void simpleTest() throws NoSuchMethodException { |
43 |
| - final Method method = EntityManager.class.getMethod("flush"); |
44 |
| - final JpaParameters parameters = new JpaParameters(method); |
45 |
| - final HibernateJpaParametersParameterAccessor accessor = new HibernateJpaParametersParameterAccessor(parameters, new Object[]{}, em); |
| 47 | + private void parametersCanGetAccessesOutsideTransaction() throws NoSuchMethodException { |
| 48 | + |
| 49 | + Method method = EntityManager.class.getMethod("flush"); |
| 50 | + JpaParameters parameters = new JpaParameters(method); |
| 51 | + HibernateJpaParametersParameterAccessor accessor = new HibernateJpaParametersParameterAccessor(parameters, |
| 52 | + new Object[] {}, em); |
46 | 53 | Assertions.assertEquals(0, accessor.getValues().length);
|
47 | 54 | Assertions.assertEquals(parameters, accessor.getParameters());
|
48 | 55 | }
|
|
0 commit comments