|
46 | 46 | * @author Oliver Gierke
|
47 | 47 | * @author Thomas Darimont
|
48 | 48 | * @author Mark Paluch
|
| 49 | + * @author Nicolas Cirigliano |
49 | 50 | */
|
50 | 51 | @RunWith(MockitoJUnitRunner.Silent.class)
|
51 | 52 | public class JpaQueryExecutionUnitTests {
|
@@ -82,18 +83,37 @@ protected Object doExecute(AbstractJpaQuery query, Object[] values) {
|
82 | 83 | }.execute(jpaQuery, new Object[] {}), is(nullValue()));
|
83 | 84 | }
|
84 | 85 |
|
| 86 | + @Test |
| 87 | + @SuppressWarnings({ "unchecked", "rawtypes" }) |
| 88 | + public void modifyingExecutionFlushesEntityManagerIfSet() { |
| 89 | + |
| 90 | + when(query.executeUpdate()).thenReturn(0); |
| 91 | + when(method.getReturnType()).thenReturn((Class) void.class); |
| 92 | + when(method.getFlushAutomatically()).thenReturn(true); |
| 93 | + when(jpaQuery.createQuery(Mockito.any(Object[].class))).thenReturn(query); |
| 94 | + when(jpaQuery.getQueryMethod()).thenReturn(method); |
| 95 | + |
| 96 | + ModifyingExecution execution = new ModifyingExecution(method, em); |
| 97 | + execution.execute(jpaQuery, new Object[] {}); |
| 98 | + |
| 99 | + verify(em, times(1)).flush(); |
| 100 | + verify(em, times(0)).clear(); |
| 101 | + } |
| 102 | + |
85 | 103 | @Test
|
86 | 104 | @SuppressWarnings({ "unchecked", "rawtypes" })
|
87 | 105 | public void modifyingExecutionClearsEntityManagerIfSet() {
|
88 | 106 |
|
89 | 107 | when(query.executeUpdate()).thenReturn(0);
|
90 | 108 | when(method.getReturnType()).thenReturn((Class) void.class);
|
| 109 | + when(method.getClearAutomatically()).thenReturn(true); |
91 | 110 | when(jpaQuery.createQuery(Mockito.any(Object[].class))).thenReturn(query);
|
92 | 111 | when(jpaQuery.getQueryMethod()).thenReturn(method);
|
93 | 112 |
|
94 | 113 | ModifyingExecution execution = new ModifyingExecution(method, em);
|
95 | 114 | execution.execute(jpaQuery, new Object[] {});
|
96 | 115 |
|
| 116 | + verify(em, times(0)).flush(); |
97 | 117 | verify(em, times(1)).clear();
|
98 | 118 | }
|
99 | 119 |
|
|
0 commit comments