@@ -149,17 +149,26 @@ public void createsQueryToFindAllEntitiesByOneOfTwoStringAttributes() throws Exc
149
149
+ ".last_name = $1 OR (" + TABLE + ".first_name = $2)" );
150
150
}
151
151
152
- @ Test // gh-282
152
+ @ Test // gh-282, gh-349
153
153
public void createsQueryToFindAllEntitiesByDateAttributeBetween () throws Exception {
154
154
155
155
R2dbcQueryMethod queryMethod = getQueryMethod ("findAllByDateOfBirthBetween" , Date .class , Date .class );
156
156
PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery (queryMethod , databaseClient , r2dbcConverter ,
157
157
dataAccessStrategy );
158
- RelationalParametersParameterAccessor accessor = getAccessor (queryMethod , new Object [] { new Date (), new Date () });
158
+ Date from = new Date ();
159
+ Date to = new Date ();
160
+ RelationalParametersParameterAccessor accessor = getAccessor (queryMethod , new Object [] { from , to });
159
161
BindableQuery bindableQuery = r2dbcQuery .createQuery (accessor );
160
162
161
163
assertThat (bindableQuery .get ())
162
164
.isEqualTo ("SELECT " + ALL_FIELDS + " FROM " + TABLE + " WHERE " + TABLE + ".date_of_birth BETWEEN $1 AND $2" );
165
+
166
+ DatabaseClient .BindSpec bindSpecMock = mock (DatabaseClient .BindSpec .class );
167
+ when (bindSpecMock .bind (anyInt (), any ())).thenReturn (bindSpecMock );
168
+ bindableQuery .bind (bindSpecMock );
169
+
170
+ verify (bindSpecMock , times (1 )).bind (0 , from );
171
+ verify (bindSpecMock , times (1 )).bind (1 , to );
163
172
}
164
173
165
174
@ Test // gh-282
@@ -559,24 +568,28 @@ public void throwsExceptionWhenInvalidNumberOfParameterIsGiven() throws Exceptio
559
568
560
569
@ Test // gh-282
561
570
public void createsQueryWithLimitToFindEntitiesByStringAttribute () throws Exception {
571
+
562
572
R2dbcQueryMethod queryMethod = getQueryMethod ("findTop3ByFirstName" , String .class );
563
573
PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery (queryMethod , databaseClient , r2dbcConverter ,
564
574
dataAccessStrategy );
565
575
RelationalParametersParameterAccessor accessor = getAccessor (queryMethod , new Object [] { "John" });
566
576
BindableQuery bindableQuery = r2dbcQuery .createQuery (accessor );
567
- String expectedSql = "SELECT " + ALL_FIELDS + " FROM " + TABLE + " WHERE " + TABLE + ".first_name = $1 LIMIT 3" ;
568
- assertThat (bindableQuery .get ()).isEqualTo (expectedSql );
577
+
578
+ assertThat (bindableQuery .get ())
579
+ .isEqualTo ("SELECT " + ALL_FIELDS + " FROM " + TABLE + " WHERE " + TABLE + ".first_name = $1 LIMIT 3" );
569
580
}
570
581
571
582
@ Test // gh-282
572
583
public void createsQueryToFindFirstEntityByStringAttribute () throws Exception {
584
+
573
585
R2dbcQueryMethod queryMethod = getQueryMethod ("findFirstByFirstName" , String .class );
574
586
PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery (queryMethod , databaseClient , r2dbcConverter ,
575
587
dataAccessStrategy );
576
588
RelationalParametersParameterAccessor accessor = getAccessor (queryMethod , new Object [] { "John" });
577
589
BindableQuery bindableQuery = r2dbcQuery .createQuery (accessor );
578
- String expectedSql = "SELECT " + ALL_FIELDS + " FROM " + TABLE + " WHERE " + TABLE + ".first_name = $1 LIMIT 1" ;
579
- assertThat (bindableQuery .get ()).isEqualTo (expectedSql );
590
+
591
+ assertThat (bindableQuery .get ())
592
+ .isEqualTo ("SELECT " + ALL_FIELDS + " FROM " + TABLE + " WHERE " + TABLE + ".first_name = $1 LIMIT 1" );
580
593
}
581
594
582
595
private R2dbcQueryMethod getQueryMethod (String methodName , Class <?>... parameterTypes ) throws Exception {
0 commit comments