DATAKV-321 - Adopt to changes in Spring Data Commons.

Update mocks with new behavior.
This commit is contained in:
Mark Paluch
2020-09-22 16:15:26 +02:00
parent 29c79f7027
commit bfd5f0152c
4 changed files with 17 additions and 0 deletions

View File

@@ -37,6 +37,7 @@ import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.query.ParametersParameterAccessor;
import org.springframework.data.repository.query.QueryMethod;
import org.springframework.data.repository.query.parser.PartTree;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.expression.spel.support.SimpleEvaluationContext;
/**
@@ -95,6 +96,7 @@ public class SpelQueryEngineUnitTests {
Method method = PersonRepository.class.getMethod(methodName, types.toArray(new Class<?>[types.size()]));
RepositoryMetadata metadata = mock(RepositoryMetadata.class);
doReturn(method.getReturnType()).when(metadata).getReturnedDomainClass(method);
doReturn(ClassTypeInformation.fromReturnTypeOf(method)).when(metadata).getReturnType(method);
PartTree partTree = new PartTree(method.getName(), method.getReturnType());
SpelQueryCreator creator = new SpelQueryCreator(partTree, new ParametersParameterAccessor(

View File

@@ -35,6 +35,7 @@ import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.query.QueryMethod;
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
import org.springframework.data.util.ClassTypeInformation;
/**
* Unit tests for {@link CachingKeyValuePartTreeQuery}.
@@ -54,6 +55,7 @@ public class CachingKeyValuePartTreeQueryUnitTests {
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
when(metadataMock.getReturnType(any(Method.class))).thenReturn(ClassTypeInformation.from((Class) List.class));
}
@Test // DATAKV-137

View File

@@ -37,9 +37,12 @@ import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.query.QueryMethod;
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
/**
* @author Christoph Strobl
* @author Mark Paluch
*/
@RunWith(MockitoJUnitRunner.class)
public class KeyValuePartTreeQueryUnitTests {
@@ -53,6 +56,8 @@ public class KeyValuePartTreeQueryUnitTests {
public void spelExpressionAndContextShouldNotBeReused() throws NoSuchMethodException, SecurityException {
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
when(metadataMock.getReturnType(any(Method.class)))
.thenReturn((TypeInformation) ClassTypeInformation.from(List.class));
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
QueryMethod qm = new QueryMethod(Repo.class.getMethod("findByFirstname", String.class), metadataMock,
@@ -74,6 +79,8 @@ public class KeyValuePartTreeQueryUnitTests {
public void shouldApplyPageableParameterToCollectionQuery() throws SecurityException, NoSuchMethodException {
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
when(metadataMock.getReturnType(any(Method.class)))
.thenReturn((TypeInformation) ClassTypeInformation.from(List.class));
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
QueryMethod qm = new QueryMethod(Repo.class.getMethod("findBy", Pageable.class), metadataMock,
@@ -93,6 +100,8 @@ public class KeyValuePartTreeQueryUnitTests {
public void shouldApplyDerivedMaxResultsToQuery() throws SecurityException, NoSuchMethodException {
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
when(metadataMock.getReturnType(any(Method.class)))
.thenReturn((TypeInformation) ClassTypeInformation.from(List.class));
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
QueryMethod qm = new QueryMethod(Repo.class.getMethod("findTop3By"), metadataMock, projectionFactoryMock);
@@ -110,6 +119,8 @@ public class KeyValuePartTreeQueryUnitTests {
public void shouldApplyDerivedMaxResultsToQueryWithParameters() throws SecurityException, NoSuchMethodException {
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
when(metadataMock.getReturnType(any(Method.class)))
.thenReturn((TypeInformation) ClassTypeInformation.from(List.class));
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
QueryMethod qm = new QueryMethod(Repo.class.getMethod("findTop3ByFirstname", String.class), metadataMock,

View File

@@ -40,6 +40,7 @@ import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.query.ParametersParameterAccessor;
import org.springframework.data.repository.query.QueryMethod;
import org.springframework.data.repository.query.parser.PartTree;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.expression.spel.standard.SpelExpression;
import org.springframework.expression.spel.support.SimpleEvaluationContext;
import org.springframework.util.ObjectUtils;
@@ -336,6 +337,7 @@ public class SpelQueryCreatorUnitTests {
Method method = PersonRepository.class.getMethod(methodName, argTypes);
doReturn(Person.class).when(metadataMock).getReturnedDomainClass(method);
doReturn(ClassTypeInformation.from(Person.class)).when(metadataMock).getReturnType(method);
PartTree partTree = new PartTree(method.getName(), method.getReturnType());
SpelQueryCreator creator = new SpelQueryCreator(partTree, new ParametersParameterAccessor(