|
39 | 39 | import org.springframework.data.util.TypeInformation; |
40 | 40 |
|
41 | 41 | /** |
| 42 | + * Unit tests for {@link KeyValuePartTreeQuery}. |
| 43 | + * |
42 | 44 | * @author Christoph Strobl |
43 | 45 | * @author Mark Paluch |
44 | 46 | */ |
@@ -175,12 +177,34 @@ void shouldUseCountForExists() throws NoSuchMethodException { |
175 | 177 | verify(kvOpsMock).exists(eq(query), eq(Person.class)); |
176 | 178 | } |
177 | 179 |
|
| 180 | + @Test // GH-71 |
| 181 | + void shouldUseCountForCount() throws NoSuchMethodException { |
| 182 | + |
| 183 | + when(metadataMock.getDomainType()).thenReturn((Class) Person.class); |
| 184 | + when(metadataMock.getDomainTypeInformation()).thenReturn((TypeInformation) TypeInformation.of(Person.class)); |
| 185 | + when(metadataMock.getReturnType(any(Method.class))).thenReturn((TypeInformation) TypeInformation.of(Boolean.class)); |
| 186 | + when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Boolean.class); |
| 187 | + |
| 188 | + QueryMethod qm = new QueryMethod(Repo.class.getMethod("countByFirstname", String.class), metadataMock, |
| 189 | + projectionFactoryMock); |
| 190 | + |
| 191 | + KeyValuePartTreeQuery partTreeQuery = new KeyValuePartTreeQuery(qm, ValueExpressionDelegate.create(), kvOpsMock, |
| 192 | + SpelQueryCreator.class); |
| 193 | + |
| 194 | + KeyValueQuery<?> query = partTreeQuery.prepareQuery(new Object[] { "firstname" }); |
| 195 | + partTreeQuery.doExecute(new Object[] { "firstname" }, query); |
| 196 | + |
| 197 | + verify(kvOpsMock).count(eq(query), eq(Person.class)); |
| 198 | + } |
| 199 | + |
178 | 200 | interface Repo { |
179 | 201 |
|
180 | 202 | List<Person> findByFirstname(String firstname); |
181 | 203 |
|
182 | 204 | boolean existsByFirstname(String firstname); |
183 | 205 |
|
| 206 | + int countByFirstname(String firstname); |
| 207 | + |
184 | 208 | List<Person> findBy(Pageable page); |
185 | 209 |
|
186 | 210 | List<Person> findTop3By(); |
|
0 commit comments