28
28
import javax .persistence .Query ;
29
29
import javax .persistence .TypedQuery ;
30
30
31
+ import org .junit .Before ;
31
32
import org .junit .Test ;
32
33
import org .junit .runner .RunWith ;
33
34
import org .mockito .Mock ;
47
48
* @author Thomas Darimont
48
49
* @author Mark Paluch
49
50
* @author Nicolas Cirigliano
51
+ * @author Jens Schauder
50
52
*/
51
53
@ RunWith (MockitoJUnitRunner .Silent .class )
52
54
public class JpaQueryExecutionUnitTests {
@@ -58,6 +60,14 @@ public class JpaQueryExecutionUnitTests {
58
60
59
61
@ Mock TypedQuery <Long > countQuery ;
60
62
63
+ @ Before
64
+ public void setUp (){
65
+
66
+ when (query .executeUpdate ()).thenReturn (0 );
67
+ when (jpaQuery .createQuery (Mockito .any (Object [].class ))).thenReturn (query );
68
+ when (jpaQuery .getQueryMethod ()).thenReturn (method );
69
+ }
70
+
61
71
@ Test (expected = IllegalArgumentException .class )
62
72
public void rejectsNullQuery () {
63
73
@@ -83,15 +93,12 @@ protected Object doExecute(AbstractJpaQuery query, Object[] values) {
83
93
}.execute (jpaQuery , new Object [] {}), is (nullValue ()));
84
94
}
85
95
86
- @ Test
96
+ @ Test // DATAJPA-806
87
97
@ SuppressWarnings ({ "unchecked" , "rawtypes" })
88
98
public void modifyingExecutionFlushesEntityManagerIfSet () {
89
99
90
- when (query .executeUpdate ()).thenReturn (0 );
91
100
when (method .getReturnType ()).thenReturn ((Class ) void .class );
92
101
when (method .getFlushAutomatically ()).thenReturn (true );
93
- when (jpaQuery .createQuery (Mockito .any (Object [].class ))).thenReturn (query );
94
- when (jpaQuery .getQueryMethod ()).thenReturn (method );
95
102
96
103
ModifyingExecution execution = new ModifyingExecution (method , em );
97
104
execution .execute (jpaQuery , new Object [] {});
@@ -104,11 +111,8 @@ public void modifyingExecutionFlushesEntityManagerIfSet() {
104
111
@ SuppressWarnings ({ "unchecked" , "rawtypes" })
105
112
public void modifyingExecutionClearsEntityManagerIfSet () {
106
113
107
- when (query .executeUpdate ()).thenReturn (0 );
108
114
when (method .getReturnType ()).thenReturn ((Class ) void .class );
109
115
when (method .getClearAutomatically ()).thenReturn (true );
110
- when (jpaQuery .createQuery (Mockito .any (Object [].class ))).thenReturn (query );
111
- when (jpaQuery .getQueryMethod ()).thenReturn (method );
112
116
113
117
ModifyingExecution execution = new ModifyingExecution (method , em );
114
118
execution .execute (jpaQuery , new Object [] {});
0 commit comments