Adopt unit tests to API changes in Commons.

Closes #475
This commit is contained in:
Mark Paluch
2023-02-15 14:14:15 +01:00
parent 5992236018
commit 928675b4e0
4 changed files with 20 additions and 15 deletions

View File

@@ -29,7 +29,6 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.data.annotation.Id;
import org.springframework.data.keyvalue.repository.query.SpelQueryCreator;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
@@ -37,7 +36,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.data.util.TypeInformation;
import org.springframework.expression.spel.support.SimpleEvaluationContext;
/**
@@ -96,7 +95,8 @@ 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);
doReturn(TypeInformation.fromReturnTypeOf(method)).when(metadata).getReturnType(method);
doReturn(TypeInformation.of(Person.class)).when(metadata).getDomainTypeInformation();
PartTree partTree = new PartTree(method.getName(), method.getReturnType());
SpelQueryCreator creator = new SpelQueryCreator(partTree, new ParametersParameterAccessor(

View File

@@ -27,7 +27,6 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.data.keyvalue.Person;
import org.springframework.data.keyvalue.core.KeyValueOperations;
import org.springframework.data.keyvalue.core.SpelCriteria;
@@ -35,7 +34,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;
import org.springframework.data.util.TypeInformation;
/**
* Unit tests for {@link CachingKeyValuePartTreeQuery}.
@@ -54,8 +53,9 @@ class CachingKeyValuePartTreeQueryUnitTests {
void setUp() throws Exception {
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
when(metadataMock.getDomainTypeInformation()).thenReturn((TypeInformation) TypeInformation.of(Person.class));
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
when(metadataMock.getReturnType(any(Method.class))).thenReturn(ClassTypeInformation.from((Class) List.class));
when(metadataMock.getReturnType(any(Method.class))).thenReturn(TypeInformation.of((Class) List.class));
}
@Test // DATAKV-137

View File

@@ -26,7 +26,6 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.keyvalue.Person;
@@ -56,6 +55,7 @@ class KeyValuePartTreeQueryUnitTests {
void spelExpressionAndContextShouldNotBeReused() throws NoSuchMethodException, SecurityException {
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
when(metadataMock.getDomainTypeInformation()).thenReturn((TypeInformation) TypeInformation.of(Person.class));
when(metadataMock.getReturnType(any(Method.class)))
.thenReturn((TypeInformation) ClassTypeInformation.from(List.class));
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
@@ -79,6 +79,7 @@ class KeyValuePartTreeQueryUnitTests {
void shouldApplyPageableParameterToCollectionQuery() throws SecurityException, NoSuchMethodException {
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
when(metadataMock.getDomainTypeInformation()).thenReturn((TypeInformation) TypeInformation.of(Person.class));
when(metadataMock.getReturnType(any(Method.class)))
.thenReturn((TypeInformation) ClassTypeInformation.from(List.class));
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
@@ -100,6 +101,7 @@ class KeyValuePartTreeQueryUnitTests {
void shouldApplyDerivedMaxResultsToQuery() throws SecurityException, NoSuchMethodException {
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
when(metadataMock.getDomainTypeInformation()).thenReturn((TypeInformation) TypeInformation.of(Person.class));
when(metadataMock.getReturnType(any(Method.class)))
.thenReturn((TypeInformation) ClassTypeInformation.from(List.class));
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
@@ -119,6 +121,7 @@ class KeyValuePartTreeQueryUnitTests {
void shouldApplyDerivedMaxResultsToQueryWithParameters() throws SecurityException, NoSuchMethodException {
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
when(metadataMock.getDomainTypeInformation()).thenReturn((TypeInformation) TypeInformation.of(Person.class));
when(metadataMock.getReturnType(any(Method.class)))
.thenReturn((TypeInformation) ClassTypeInformation.from(List.class));
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
@@ -141,6 +144,7 @@ class KeyValuePartTreeQueryUnitTests {
void shouldUseCountForExists() throws NoSuchMethodException {
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
when(metadataMock.getDomainTypeInformation()).thenReturn((TypeInformation) TypeInformation.of(Person.class));
when(metadataMock.getReturnType(any(Method.class)))
.thenReturn((TypeInformation) ClassTypeInformation.from(Boolean.class));
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Boolean.class);

View File

@@ -15,9 +15,11 @@
*/
package org.springframework.data.keyvalue.repository.query;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.Mockito.doReturn;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import lombok.Data;
import lombok.SneakyThrows;
import java.lang.reflect.Method;
import java.time.ZonedDateTime;
@@ -29,23 +31,21 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.annotation.Id;
import org.springframework.data.keyvalue.core.query.KeyValueQuery;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.data.repository.CrudRepository;
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.data.util.TypeInformation;
import org.springframework.expression.spel.standard.SpelExpression;
import org.springframework.expression.spel.support.SimpleEvaluationContext;
import org.springframework.util.ObjectUtils;
import lombok.Data;
import lombok.SneakyThrows;
/**
* @author Christoph Strobl
* @author Mark Paluch
@@ -338,6 +338,7 @@ public class SpelQueryCreatorUnitTests {
Method method = PersonRepository.class.getMethod(methodName, argTypes);
doReturn(Person.class).when(metadataMock).getReturnedDomainClass(method);
doReturn(TypeInformation.of(Person.class)).when(metadataMock).getDomainTypeInformation();
doReturn(ClassTypeInformation.from(Person.class)).when(metadataMock).getReturnType(method);
PartTree partTree = new PartTree(method.getName(), method.getReturnType());
@@ -352,7 +353,7 @@ public class SpelQueryCreatorUnitTests {
}
@SuppressWarnings("unused")
interface PersonRepository {
interface PersonRepository extends CrudRepository<Person, String> {
// No arguments
Person findBy();