Skip to content

Commit d88d499

Browse files
committed
Adopt unit tests to API changes in Commons.
Closes #475
1 parent 63d4711 commit d88d499

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

src/test/java/org/springframework/data/keyvalue/core/SpelQueryEngineUnitTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,14 @@
2929
import org.junit.jupiter.api.extension.ExtendWith;
3030
import org.mockito.Mock;
3131
import org.mockito.junit.jupiter.MockitoExtension;
32-
3332
import org.springframework.data.annotation.Id;
3433
import org.springframework.data.keyvalue.repository.query.SpelQueryCreator;
3534
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
3635
import org.springframework.data.repository.core.RepositoryMetadata;
3736
import org.springframework.data.repository.query.ParametersParameterAccessor;
3837
import org.springframework.data.repository.query.QueryMethod;
3938
import org.springframework.data.repository.query.parser.PartTree;
40-
import org.springframework.data.util.ClassTypeInformation;
39+
import org.springframework.data.util.TypeInformation;
4140
import org.springframework.expression.spel.support.SimpleEvaluationContext;
4241

4342
/**
@@ -96,7 +95,8 @@ private static SpelCriteria createQueryForMethodWithArgs(String methodName, Obje
9695
Method method = PersonRepository.class.getMethod(methodName, types.toArray(new Class<?>[types.size()]));
9796
RepositoryMetadata metadata = mock(RepositoryMetadata.class);
9897
doReturn(method.getReturnType()).when(metadata).getReturnedDomainClass(method);
99-
doReturn(ClassTypeInformation.fromReturnTypeOf(method)).when(metadata).getReturnType(method);
98+
doReturn(TypeInformation.fromReturnTypeOf(method)).when(metadata).getReturnType(method);
99+
doReturn(TypeInformation.of(Person.class)).when(metadata).getDomainTypeInformation();
100100

101101
PartTree partTree = new PartTree(method.getName(), method.getReturnType());
102102
SpelQueryCreator creator = new SpelQueryCreator(partTree, new ParametersParameterAccessor(

src/test/java/org/springframework/data/keyvalue/repository/query/CachingKeyValuePartTreeQueryUnitTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@
2727
import org.junit.jupiter.api.extension.ExtendWith;
2828
import org.mockito.Mock;
2929
import org.mockito.junit.jupiter.MockitoExtension;
30-
3130
import org.springframework.data.keyvalue.Person;
3231
import org.springframework.data.keyvalue.core.KeyValueOperations;
3332
import org.springframework.data.keyvalue.core.SpelCriteria;
3433
import org.springframework.data.projection.ProjectionFactory;
3534
import org.springframework.data.repository.core.RepositoryMetadata;
3635
import org.springframework.data.repository.query.QueryMethod;
3736
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
38-
import org.springframework.data.util.ClassTypeInformation;
37+
import org.springframework.data.util.TypeInformation;
3938

4039
/**
4140
* Unit tests for {@link CachingKeyValuePartTreeQuery}.
@@ -54,8 +53,9 @@ class CachingKeyValuePartTreeQueryUnitTests {
5453
void setUp() throws Exception {
5554

5655
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
56+
when(metadataMock.getDomainTypeInformation()).thenReturn((TypeInformation) TypeInformation.of(Person.class));
5757
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
58-
when(metadataMock.getReturnType(any(Method.class))).thenReturn(ClassTypeInformation.from((Class) List.class));
58+
when(metadataMock.getReturnType(any(Method.class))).thenReturn(TypeInformation.of((Class) List.class));
5959
}
6060

6161
@Test // DATAKV-137

src/test/java/org/springframework/data/keyvalue/repository/query/KeyValuePartTreeQueryUnitTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.junit.jupiter.api.extension.ExtendWith;
2727
import org.mockito.Mock;
2828
import org.mockito.junit.jupiter.MockitoExtension;
29-
3029
import org.springframework.data.domain.PageRequest;
3130
import org.springframework.data.domain.Pageable;
3231
import org.springframework.data.keyvalue.Person;
@@ -56,6 +55,7 @@ class KeyValuePartTreeQueryUnitTests {
5655
void spelExpressionAndContextShouldNotBeReused() throws NoSuchMethodException, SecurityException {
5756

5857
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
58+
when(metadataMock.getDomainTypeInformation()).thenReturn((TypeInformation) TypeInformation.of(Person.class));
5959
when(metadataMock.getReturnType(any(Method.class)))
6060
.thenReturn((TypeInformation) ClassTypeInformation.from(List.class));
6161
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
@@ -79,6 +79,7 @@ void spelExpressionAndContextShouldNotBeReused() throws NoSuchMethodException, S
7979
void shouldApplyPageableParameterToCollectionQuery() throws SecurityException, NoSuchMethodException {
8080

8181
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
82+
when(metadataMock.getDomainTypeInformation()).thenReturn((TypeInformation) TypeInformation.of(Person.class));
8283
when(metadataMock.getReturnType(any(Method.class)))
8384
.thenReturn((TypeInformation) ClassTypeInformation.from(List.class));
8485
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
@@ -100,6 +101,7 @@ void shouldApplyPageableParameterToCollectionQuery() throws SecurityException, N
100101
void shouldApplyDerivedMaxResultsToQuery() throws SecurityException, NoSuchMethodException {
101102

102103
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
104+
when(metadataMock.getDomainTypeInformation()).thenReturn((TypeInformation) TypeInformation.of(Person.class));
103105
when(metadataMock.getReturnType(any(Method.class)))
104106
.thenReturn((TypeInformation) ClassTypeInformation.from(List.class));
105107
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
@@ -119,6 +121,7 @@ void shouldApplyDerivedMaxResultsToQuery() throws SecurityException, NoSuchMetho
119121
void shouldApplyDerivedMaxResultsToQueryWithParameters() throws SecurityException, NoSuchMethodException {
120122

121123
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
124+
when(metadataMock.getDomainTypeInformation()).thenReturn((TypeInformation) TypeInformation.of(Person.class));
122125
when(metadataMock.getReturnType(any(Method.class)))
123126
.thenReturn((TypeInformation) ClassTypeInformation.from(List.class));
124127
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
@@ -141,6 +144,7 @@ void shouldApplyDerivedMaxResultsToQueryWithParameters() throws SecurityExceptio
141144
void shouldUseCountForExists() throws NoSuchMethodException {
142145

143146
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
147+
when(metadataMock.getDomainTypeInformation()).thenReturn((TypeInformation) TypeInformation.of(Person.class));
144148
when(metadataMock.getReturnType(any(Method.class)))
145149
.thenReturn((TypeInformation) ClassTypeInformation.from(Boolean.class));
146150
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Boolean.class);

src/test/java/org/springframework/data/keyvalue/repository/query/SpelQueryCreatorUnitTests.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
*/
1616
package org.springframework.data.keyvalue.repository.query;
1717

18-
import static org.assertj.core.api.Assertions.assertThat;
19-
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
20-
import static org.mockito.Mockito.doReturn;
18+
import static org.assertj.core.api.Assertions.*;
19+
import static org.mockito.Mockito.*;
20+
21+
import lombok.Data;
22+
import lombok.SneakyThrows;
2123

2224
import java.lang.reflect.Method;
2325
import java.time.ZonedDateTime;
@@ -29,23 +31,21 @@
2931
import org.junit.jupiter.api.extension.ExtendWith;
3032
import org.mockito.Mock;
3133
import org.mockito.junit.jupiter.MockitoExtension;
32-
3334
import org.springframework.dao.InvalidDataAccessApiUsageException;
3435
import org.springframework.data.annotation.Id;
3536
import org.springframework.data.keyvalue.core.query.KeyValueQuery;
3637
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
38+
import org.springframework.data.repository.CrudRepository;
3739
import org.springframework.data.repository.core.RepositoryMetadata;
3840
import org.springframework.data.repository.query.ParametersParameterAccessor;
3941
import org.springframework.data.repository.query.QueryMethod;
4042
import org.springframework.data.repository.query.parser.PartTree;
4143
import org.springframework.data.util.ClassTypeInformation;
44+
import org.springframework.data.util.TypeInformation;
4245
import org.springframework.expression.spel.standard.SpelExpression;
4346
import org.springframework.expression.spel.support.SimpleEvaluationContext;
4447
import org.springframework.util.ObjectUtils;
4548

46-
import lombok.Data;
47-
import lombok.SneakyThrows;
48-
4949
/**
5050
* @author Christoph Strobl
5151
* @author Mark Paluch
@@ -338,6 +338,7 @@ private KeyValueQuery<SpelExpression> createQueryForMethodWithArgs(String method
338338

339339
Method method = PersonRepository.class.getMethod(methodName, argTypes);
340340
doReturn(Person.class).when(metadataMock).getReturnedDomainClass(method);
341+
doReturn(TypeInformation.of(Person.class)).when(metadataMock).getDomainTypeInformation();
341342
doReturn(ClassTypeInformation.from(Person.class)).when(metadataMock).getReturnType(method);
342343

343344
PartTree partTree = new PartTree(method.getName(), method.getReturnType());
@@ -352,7 +353,7 @@ private KeyValueQuery<SpelExpression> createQueryForMethodWithArgs(String method
352353
}
353354

354355
@SuppressWarnings("unused")
355-
interface PersonRepository {
356+
interface PersonRepository extends CrudRepository<Person, String> {
356357

357358
// No arguments
358359
Person findBy();

0 commit comments

Comments
 (0)