Skip to content

Commit cf0fe0c

Browse files
committed
#373 - Extract test into ExpressionQueryUnitTests.
1 parent bc73cf1 commit cf0fe0c

File tree

2 files changed

+44
-20
lines changed

2 files changed

+44
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.r2dbc.repository.query;
17+
18+
import static org.assertj.core.api.Assertions.*;
19+
20+
import org.junit.Test;
21+
22+
/**
23+
* Unit tests for {@link ExpressionQuery}.
24+
*
25+
* @author Mark Paluch
26+
*/
27+
public class ExpressionQueryUnitTests {
28+
29+
@Test // gh-373
30+
public void bindsMultipleSpelParametersCorrectly() {
31+
32+
ExpressionQuery query = ExpressionQuery
33+
.create("INSERT IGNORE INTO table (x, y) VALUES (:#{#point.x}, :#{#point.y})");
34+
35+
assertThat(query.getQuery())
36+
.isEqualTo("INSERT IGNORE INTO table (x, y) VALUES (:__synthetic_0__, :__synthetic_1__)");
37+
38+
assertThat(query.getBindings()).hasSize(2);
39+
assertThat(query.getBindings().get(0).getExpression()).isEqualTo("#point.x");
40+
assertThat(query.getBindings().get(0).getParameterName()).isEqualTo("__synthetic_0__");
41+
assertThat(query.getBindings().get(1).getExpression()).isEqualTo("#point.y");
42+
assertThat(query.getBindings().get(1).getParameterName()).isEqualTo("__synthetic_1__");
43+
}
44+
}

src/test/java/org/springframework/data/r2dbc/repository/query/StringBasedR2dbcQueryUnitTests.java

-20
Original file line numberDiff line numberDiff line change
@@ -238,23 +238,6 @@ public void skipsNonBindableParameters() {
238238
verifyNoMoreInteractions(bindSpec);
239239
}
240240

241-
@Test // gh-373
242-
public void bindsMultipleSpelParametersCorrectly() {
243-
244-
StringBasedR2dbcQuery query = getQueryMethod("queryWithTwoSpelExpressions", Point.class);
245-
R2dbcParameterAccessor accessor = new R2dbcParameterAccessor(query.getQueryMethod(), new Point(1, 2));
246-
247-
BindableQuery stringQuery = query.createQuery(accessor);
248-
249-
assertThat(stringQuery.get())
250-
.isEqualTo("INSERT IGNORE INTO table (x, y) VALUES (:__synthetic_0__, :__synthetic_1__)");
251-
assertThat(stringQuery.bind(bindSpec)).isNotNull();
252-
253-
verify(bindSpec).bind("__synthetic_0__", 1d);
254-
verify(bindSpec).bind("__synthetic_1__", 2d);
255-
verifyNoMoreInteractions(bindSpec);
256-
}
257-
258241
private StringBasedR2dbcQuery getQueryMethod(String name, Class<?>... args) {
259242

260243
Method method = ReflectionUtils.findMethod(SampleRepository.class, name, args);
@@ -300,9 +283,6 @@ private interface SampleRepository extends Repository<Person, String> {
300283

301284
@Query("SELECT * FROM person WHERE lastname = :name")
302285
Person queryWithUnusedParameter(String name, Sort unused);
303-
304-
@Query("INSERT IGNORE INTO table (x, y) VALUES (:#{#point.x}, :#{#point.y})")
305-
Person queryWithTwoSpelExpressions(@Param("point") Point point);
306286
}
307287

308288
static class Person {

0 commit comments

Comments
 (0)