18
18
import static org .assertj .core .api .Assertions .*;
19
19
import static org .mockito .Mockito .*;
20
20
21
+ import io .r2dbc .spi .Connection ;
21
22
import io .r2dbc .spi .Statement ;
22
23
23
24
import java .util .Arrays ;
@@ -46,6 +47,11 @@ public class StatementFactoryUnitTests {
46
47
.createRenderContext ());
47
48
48
49
Statement statementMock = mock (Statement .class );
50
+ Connection connectionMock = mock (Connection .class );
51
+
52
+ {
53
+ when (connectionMock .createStatement (anyString ())).thenReturn (statementMock );
54
+ }
49
55
50
56
@ Test
51
57
public void shouldToQuerySimpleSelectWithoutBindings () {
@@ -55,7 +61,8 @@ public void shouldToQuerySimpleSelectWithoutBindings() {
55
61
assertThat (select .getSource ()).isInstanceOf (Select .class );
56
62
assertThat (select .toQuery ()).isEqualTo ("SELECT foo.bar, foo.baz FROM foo" );
57
63
58
- select .bind (statementMock );
64
+ select .bind (connectionMock );
65
+
59
66
verifyZeroInteractions (statementMock );
60
67
}
61
68
@@ -69,7 +76,8 @@ public void shouldToQuerySimpleSelectWithSimpleFilter() {
69
76
assertThat (select .getSource ()).isInstanceOf (Select .class );
70
77
assertThat (select .toQuery ()).isEqualTo ("SELECT foo.bar, foo.baz FROM foo WHERE foo.doe = $1" );
71
78
72
- select .bind (statementMock );
79
+ select .bind (connectionMock );
80
+
73
81
verify (statementMock ).bind (0 , "John" );
74
82
verifyNoMoreInteractions (statementMock );
75
83
}
@@ -85,7 +93,8 @@ public void shouldToQuerySimpleSelectWithMultipleFilters() {
85
93
assertThat (select .getSource ()).isInstanceOf (Select .class );
86
94
assertThat (select .toQuery ()).isEqualTo ("SELECT foo.bar, foo.baz FROM foo WHERE foo.doe = $1 AND foo.baz = $2" );
87
95
88
- select .bind (statementMock );
96
+ select .bind (connectionMock );
97
+
89
98
verify (statementMock ).bind (0 , "John" );
90
99
verify (statementMock ).bind (1 , "Jake" );
91
100
verifyNoMoreInteractions (statementMock );
@@ -101,7 +110,7 @@ public void shouldToQuerySimpleSelectWithNullFilter() {
101
110
assertThat (select .getSource ()).isInstanceOf (Select .class );
102
111
assertThat (select .toQuery ()).isEqualTo ("SELECT foo.bar, foo.baz FROM foo WHERE foo.doe IS NULL" );
103
112
104
- select .bind (statementMock );
113
+ select .bind (connectionMock );
105
114
verifyZeroInteractions (statementMock );
106
115
}
107
116
@@ -115,7 +124,7 @@ public void shouldToQuerySimpleSelectWithIterableFilter() {
115
124
assertThat (select .getSource ()).isInstanceOf (Select .class );
116
125
assertThat (select .toQuery ()).isEqualTo ("SELECT foo.bar, foo.baz FROM foo WHERE foo.doe IN ($1, $2)" );
117
126
118
- select .bind (statementMock );
127
+ select .bind (connectionMock );
119
128
verify (statementMock ).bind (0 , "John" );
120
129
verify (statementMock ).bind (1 , "Jake" );
121
130
verifyNoMoreInteractions (statementMock );
@@ -138,7 +147,7 @@ public void shouldToQuerySimpleInsert() {
138
147
assertThat (insert .getSource ()).isInstanceOf (Insert .class );
139
148
assertThat (insert .toQuery ()).isEqualTo ("INSERT INTO foo (bar) VALUES ($1)" );
140
149
141
- insert .bind (statementMock );
150
+ insert .bind (connectionMock );
142
151
verify (statementMock ).bind (0 , "Foo" );
143
152
verify (statementMock ).returnGeneratedValues (any (String [].class ));
144
153
verifyNoMoreInteractions (statementMock );
@@ -161,7 +170,7 @@ public void shouldToQuerySimpleUpdate() {
161
170
assertThat (update .getSource ()).isInstanceOf (Update .class );
162
171
assertThat (update .toQuery ()).isEqualTo ("UPDATE foo SET bar = $1" );
163
172
164
- update .bind (statementMock );
173
+ update .bind (connectionMock );
165
174
verify (statementMock ).bind (0 , "Foo" );
166
175
verifyNoMoreInteractions (statementMock );
167
176
}
@@ -176,7 +185,7 @@ public void shouldToQueryNullUpdate() {
176
185
assertThat (update .getSource ()).isInstanceOf (Update .class );
177
186
assertThat (update .toQuery ()).isEqualTo ("UPDATE foo SET bar = $1" );
178
187
179
- update .bind (statementMock );
188
+ update .bind (connectionMock );
180
189
verify (statementMock ).bindNull (0 , String .class );
181
190
182
191
verifyNoMoreInteractions (statementMock );
@@ -193,7 +202,7 @@ public void shouldToQueryUpdateWithFilter() {
193
202
assertThat (update .getSource ()).isInstanceOf (Update .class );
194
203
assertThat (update .toQuery ()).isEqualTo ("UPDATE foo SET bar = $1 WHERE foo.baz = $2" );
195
204
196
- update .bind (statementMock );
205
+ update .bind (connectionMock );
197
206
verify (statementMock ).bind (0 , "Foo" );
198
207
verify (statementMock ).bind (1 , "Baz" );
199
208
verifyNoMoreInteractions (statementMock );
@@ -209,7 +218,7 @@ public void shouldToQuerySimpleDeleteWithSimpleFilter() {
209
218
assertThat (delete .getSource ()).isInstanceOf (Delete .class );
210
219
assertThat (delete .toQuery ()).isEqualTo ("DELETE FROM foo WHERE foo.doe = $1" );
211
220
212
- delete .bind (statementMock );
221
+ delete .bind (connectionMock );
213
222
verify (statementMock ).bind (0 , "John" );
214
223
verifyNoMoreInteractions (statementMock );
215
224
}
@@ -225,7 +234,7 @@ public void shouldToQuerySimpleDeleteWithMultipleFilters() {
225
234
assertThat (delete .getSource ()).isInstanceOf (Delete .class );
226
235
assertThat (delete .toQuery ()).isEqualTo ("DELETE FROM foo WHERE foo.doe = $1 AND foo.baz = $2" );
227
236
228
- delete .bind (statementMock );
237
+ delete .bind (connectionMock );
229
238
verify (statementMock ).bind (0 , "John" );
230
239
verify (statementMock ).bind (1 , "Jake" );
231
240
verifyNoMoreInteractions (statementMock );
@@ -241,7 +250,7 @@ public void shouldToQuerySimpleDeleteWithNullFilter() {
241
250
assertThat (delete .getSource ()).isInstanceOf (Delete .class );
242
251
assertThat (delete .toQuery ()).isEqualTo ("DELETE FROM foo WHERE foo.doe IS NULL" );
243
252
244
- delete .bind (statementMock );
253
+ delete .bind (connectionMock );
245
254
verifyZeroInteractions (statementMock );
246
255
}
247
256
}
0 commit comments