Polishing.
Move off deprecated API in tests. See #3305 Original pull request: #3307
This commit is contained in:
@@ -25,10 +25,10 @@ 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.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.core.type.StandardAnnotationMetadata;
|
||||
import org.springframework.data.auditing.EnableAuditing;
|
||||
|
||||
/**
|
||||
@@ -48,7 +48,7 @@ class AuditingBeanDefinitionRegistrarSupportUnitTests {
|
||||
void testRegisterBeanDefinitions() {
|
||||
|
||||
AuditingBeanDefinitionRegistrarSupport registrar = new DummyAuditingBeanDefinitionRegistrarSupport();
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(SampleConfig.class);
|
||||
AnnotationMetadata metadata = AnnotationMetadata.introspect(SampleConfig.class);
|
||||
|
||||
registrar.registerBeanDefinitions(metadata, registry);
|
||||
verify(registry, times(1)).registerBeanDefinition(anyString(), any(BeanDefinition.class));
|
||||
@@ -67,7 +67,7 @@ class AuditingBeanDefinitionRegistrarSupportUnitTests {
|
||||
void rejectsNullRegistry() {
|
||||
|
||||
AuditingBeanDefinitionRegistrarSupport registrar = new DummyAuditingBeanDefinitionRegistrarSupport();
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(SampleConfig.class);
|
||||
AnnotationMetadata metadata = AnnotationMetadata.introspect(SampleConfig.class);
|
||||
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> registrar.registerBeanDefinitions(metadata, null));
|
||||
|
||||
@@ -68,7 +68,8 @@ public class ClassGeneratingPropertyAccessorFactoryTests {
|
||||
Class<Object> defaultPackageClass = (Class) Class.forName("TypeInDefaultPackage");
|
||||
|
||||
parameters
|
||||
.add(new Object[] { defaultPackageClass.newInstance(), "", defaultPackageClass, "Class in default package" });
|
||||
.add(new Object[] { defaultPackageClass.getConstructor().newInstance(), "", defaultPackageClass,
|
||||
"Class in default package" });
|
||||
|
||||
return parameters;
|
||||
}
|
||||
|
||||
@@ -29,13 +29,13 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.aop.Advisor;
|
||||
import org.springframework.aop.TargetClassAware;
|
||||
import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
/**
|
||||
@@ -397,7 +397,8 @@ class ProxyProjectionFactoryUnitTests {
|
||||
|
||||
interface CustomerProjectionWithNullables {
|
||||
|
||||
@Nullable String getFirstname();
|
||||
@Nullable
|
||||
String getFirstname();
|
||||
String getLastname();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ import java.lang.annotation.Annotation;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.core.annotation.MergedAnnotation;
|
||||
import org.springframework.core.env.Environment;
|
||||
@@ -29,7 +31,6 @@ import org.springframework.data.repository.config.AotRepositoryContext;
|
||||
import org.springframework.data.repository.config.RepositoryConfigurationSource;
|
||||
import org.springframework.data.repository.core.RepositoryInformation;
|
||||
import org.springframework.data.repository.core.support.RepositoryComposition;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Dummy {@link AotRepositoryContext} used to simulate module specific repository implementation.
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.springframework.data.repository.core.RepositoryInformation;
|
||||
import org.springframework.data.repository.core.support.RepositoryComposition;
|
||||
import org.springframework.data.repository.core.support.RepositoryComposition.RepositoryFragments;
|
||||
import org.springframework.data.repository.core.support.RepositoryFragment;
|
||||
import org.springframework.data.repository.query.DefaultParameters;
|
||||
import org.springframework.data.repository.query.QueryMethod;
|
||||
import org.springframework.javapoet.CodeBlock;
|
||||
import org.springframework.util.ClassUtils;
|
||||
@@ -61,7 +62,8 @@ class RepositoryContributorUnitTests {
|
||||
protected @Nullable MethodContributor<? extends QueryMethod> contributeQueryMethod(Method method) {
|
||||
|
||||
return MethodContributor
|
||||
.forQueryMethod(new QueryMethod(method, getRepositoryInformation(), getProjectionFactory()))
|
||||
.forQueryMethod(
|
||||
new QueryMethod(method, getRepositoryInformation(), getProjectionFactory(), DefaultParameters::new))
|
||||
.withMetadata(new QueryMetadata() {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,6 +19,8 @@ import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.data.repository.core.CrudMethods;
|
||||
import org.springframework.data.repository.core.RepositoryInformation;
|
||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
@@ -26,7 +28,6 @@ import org.springframework.data.repository.core.support.AbstractRepositoryMetada
|
||||
import org.springframework.data.repository.core.support.RepositoryComposition;
|
||||
import org.springframework.data.repository.core.support.RepositoryFragment;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Stub {@link RepositoryInformation} used for testing.
|
||||
|
||||
@@ -34,7 +34,6 @@ import org.springframework.core.env.StandardEnvironment;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.core.type.StandardAnnotationMetadata;
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
import org.springframework.data.repository.config.basepackage.repo.PersonRepository;
|
||||
import org.springframework.data.repository.core.support.DummyReactiveRepositoryFactory;
|
||||
@@ -59,7 +58,7 @@ class AnnotationRepositoryConfigurationSourceUnitTests {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
AnnotationMetadata annotationMetadata = new StandardAnnotationMetadata(SampleConfiguration.class, true);
|
||||
AnnotationMetadata annotationMetadata = AnnotationMetadata.introspect(SampleConfiguration.class);
|
||||
environment = new StandardEnvironment();
|
||||
resourceLoader = new DefaultResourceLoader();
|
||||
registry = mock(BeanDefinitionRegistry.class);
|
||||
@@ -120,8 +119,7 @@ class AnnotationRepositoryConfigurationSourceUnitTests {
|
||||
@Test // DATACMNS-502
|
||||
void returnsEmptyStringForBasePackage() throws Exception {
|
||||
|
||||
var metadata = new StandardAnnotationMetadata(
|
||||
getClass().getClassLoader().loadClass("TypeInDefaultPackage"), true);
|
||||
var metadata = AnnotationMetadata.introspect(getClass().getClassLoader().loadClass("TypeInDefaultPackage"));
|
||||
RepositoryConfigurationSource configurationSource = new AnnotationRepositoryConfigurationSource(metadata,
|
||||
EnableRepositories.class, resourceLoader, environment, registry, null);
|
||||
|
||||
@@ -138,7 +136,7 @@ class AnnotationRepositoryConfigurationSourceUnitTests {
|
||||
@Test // DATACMNS-542
|
||||
void ignoresMissingRepositoryBaseClassNameAttribute() {
|
||||
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(ConfigWithSampleAnnotation.class, true);
|
||||
AnnotationMetadata metadata = AnnotationMetadata.introspect(ConfigWithSampleAnnotation.class);
|
||||
RepositoryConfigurationSource configurationSource = new AnnotationRepositoryConfigurationSource(metadata,
|
||||
SampleAnnotation.class, resourceLoader, environment, registry, null);
|
||||
|
||||
@@ -190,7 +188,7 @@ class AnnotationRepositoryConfigurationSourceUnitTests {
|
||||
RootBeanDefinition bd = new RootBeanDefinition(DummyRepositoryFactory.class);
|
||||
bd.getConstructorArgumentValues().addGenericArgumentValue(PersonRepository.class);
|
||||
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(ConfigurationWithFragmentsContributor.class, true);
|
||||
AnnotationMetadata metadata = AnnotationMetadata.introspect(ConfigurationWithFragmentsContributor.class);
|
||||
AnnotationRepositoryConfigurationSource configurationSource = new AnnotationRepositoryConfigurationSource(metadata,
|
||||
EnableRepositoriesWithContributor.class, resourceLoader, environment, registry, null);
|
||||
|
||||
@@ -204,8 +202,7 @@ class AnnotationRepositoryConfigurationSourceUnitTests {
|
||||
RootBeanDefinition bd = new RootBeanDefinition(DummyRepositoryFactory.class);
|
||||
bd.getConstructorArgumentValues().addGenericArgumentValue(PersonRepository.class);
|
||||
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(ReactiveConfigurationWithBeanNameGenerator.class,
|
||||
true);
|
||||
AnnotationMetadata metadata = AnnotationMetadata.introspect(ReactiveConfigurationWithBeanNameGenerator.class);
|
||||
AnnotationRepositoryConfigurationSource configurationSource = new AnnotationRepositoryConfigurationSource(metadata,
|
||||
EnableReactiveRepositories.class, resourceLoader, environment, registry, null);
|
||||
|
||||
@@ -225,7 +222,7 @@ class AnnotationRepositoryConfigurationSourceUnitTests {
|
||||
|
||||
private AnnotationRepositoryConfigurationSource getConfigSource(Class<?> type) {
|
||||
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(type, true);
|
||||
AnnotationMetadata metadata = AnnotationMetadata.introspect(type);
|
||||
return new AnnotationRepositoryConfigurationSource(metadata, EnableRepositories.class, resourceLoader, environment,
|
||||
registry, null);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ import org.springframework.context.annotation.FilterType;
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.core.type.StandardAnnotationMetadata;
|
||||
import org.springframework.data.mapping.Person;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.config.basepackage.FragmentImpl;
|
||||
@@ -67,7 +66,7 @@ class RepositoryBeanDefinitionRegistrarSupportUnitTests {
|
||||
@Test
|
||||
void registersBeanDefinitionForFoundBean() {
|
||||
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(SampleConfiguration.class, true);
|
||||
AnnotationMetadata metadata = AnnotationMetadata.introspect(SampleConfiguration.class);
|
||||
|
||||
registrar.registerBeanDefinitions(metadata, registry);
|
||||
|
||||
@@ -81,7 +80,7 @@ class RepositoryBeanDefinitionRegistrarSupportUnitTests {
|
||||
@Test // GH-2584
|
||||
void shouldExposeFragmentsAsBean() {
|
||||
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(SampleConfiguration.class, true);
|
||||
AnnotationMetadata metadata = AnnotationMetadata.introspect(SampleConfiguration.class);
|
||||
|
||||
registrar.registerBeanDefinitions(metadata, registry);
|
||||
verify(registry, atLeast(1)).registerBeanDefinition(eq("commons.MyRepository.fragments#0"),
|
||||
@@ -103,7 +102,7 @@ class RepositoryBeanDefinitionRegistrarSupportUnitTests {
|
||||
@Test // DATACMNS-1147
|
||||
void registersBeanDefinitionWithoutFragmentImplementations() {
|
||||
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(FragmentExclusionConfiguration.class, true);
|
||||
AnnotationMetadata metadata = AnnotationMetadata.introspect(FragmentExclusionConfiguration.class);
|
||||
|
||||
registrar.registerBeanDefinitions(metadata, registry);
|
||||
|
||||
@@ -114,7 +113,7 @@ class RepositoryBeanDefinitionRegistrarSupportUnitTests {
|
||||
@Test // DATACMNS-1172, GH-3090
|
||||
void shouldLimitImplementationBasePackages() {
|
||||
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(LimitsImplementationBasePackages.class, true);
|
||||
AnnotationMetadata metadata = AnnotationMetadata.introspect(LimitsImplementationBasePackages.class);
|
||||
|
||||
registrar.registerBeanDefinitions(metadata, registry);
|
||||
|
||||
@@ -127,7 +126,7 @@ class RepositoryBeanDefinitionRegistrarSupportUnitTests {
|
||||
@Test // DATACMNS-360
|
||||
void registeredProfileRepositoriesIfProfileActivated() {
|
||||
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(SampleConfiguration.class, true);
|
||||
AnnotationMetadata metadata = AnnotationMetadata.introspect(SampleConfiguration.class);
|
||||
environment.setActiveProfiles("profile");
|
||||
|
||||
var registrar = new DummyRegistrar();
|
||||
@@ -140,7 +139,7 @@ class RepositoryBeanDefinitionRegistrarSupportUnitTests {
|
||||
@Test // DATACMNS-1497
|
||||
void usesBeanNameGeneratorProvided() {
|
||||
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(SampleConfiguration.class, true);
|
||||
AnnotationMetadata metadata = AnnotationMetadata.introspect(SampleConfiguration.class);
|
||||
BeanNameGenerator delegate = new AnnotationBeanNameGenerator();
|
||||
|
||||
var registrar = new DummyRegistrar();
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
@@ -32,7 +33,6 @@ import org.springframework.core.env.StandardEnvironment;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.core.type.StandardAnnotationMetadata;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.Repository;
|
||||
@@ -74,7 +74,7 @@ class RepositoryConfigurationExtensionSupportUnitTests {
|
||||
@Test // DATACMNS-1174
|
||||
void rejectsReactiveRepositories() {
|
||||
|
||||
AnnotationMetadata annotationMetadata = new StandardAnnotationMetadata(ReactiveConfiguration.class, true);
|
||||
AnnotationMetadata annotationMetadata = AnnotationMetadata.introspect(ReactiveConfiguration.class);
|
||||
Environment environment = new StandardEnvironment();
|
||||
ResourceLoader resourceLoader = new DefaultResourceLoader();
|
||||
var registry = mock(BeanDefinitionRegistry.class);
|
||||
|
||||
@@ -70,33 +70,35 @@ class QueryMethodUnitTests {
|
||||
|
||||
var method = SampleRepository.class.getMethod("pagingMethodWithInvalidReturnType", Pageable.class);
|
||||
|
||||
assertThatIllegalStateException().isThrownBy(() -> new QueryMethod(method, metadata, factory));
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> new QueryMethod(method, metadata, factory, DefaultParameters::new));
|
||||
}
|
||||
|
||||
@Test // DATAJPA-59
|
||||
void rejectsPagingMethodWithoutPageable() throws Exception {
|
||||
var method = SampleRepository.class.getMethod("pagingMethodWithoutPageable");
|
||||
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new QueryMethod(method, metadata, factory));
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new QueryMethod(method, metadata, factory, DefaultParameters::new));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-64
|
||||
void setsUpSimpleQueryMethodCorrectly() throws Exception {
|
||||
var method = SampleRepository.class.getMethod("findByUsername", String.class);
|
||||
new QueryMethod(method, metadata, factory);
|
||||
new QueryMethod(method, metadata, factory, DefaultParameters::new);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-61
|
||||
void considersIterableMethodForCollectionQuery() throws Exception {
|
||||
var method = SampleRepository.class.getMethod("sampleMethod");
|
||||
var queryMethod = new QueryMethod(method, metadata, factory);
|
||||
var queryMethod = new QueryMethod(method, metadata, factory, DefaultParameters::new);
|
||||
assertThat(queryMethod.isCollectionQuery()).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-67
|
||||
void doesNotConsiderPageMethodCollectionQuery() throws Exception {
|
||||
var method = SampleRepository.class.getMethod("anotherSampleMethod", Pageable.class);
|
||||
var queryMethod = new QueryMethod(method, metadata, factory);
|
||||
var queryMethod = new QueryMethod(method, metadata, factory, DefaultParameters::new);
|
||||
assertThat(queryMethod.isPageQuery()).isTrue();
|
||||
assertThat(queryMethod.isCollectionQuery()).isFalse();
|
||||
}
|
||||
@@ -104,7 +106,7 @@ class QueryMethodUnitTests {
|
||||
@Test // GH-2151
|
||||
void supportsImperativecursorQueries() throws Exception {
|
||||
var method = SampleRepository.class.getMethod("cursorWindow", ScrollPosition.class);
|
||||
var queryMethod = new QueryMethod(method, metadata, factory);
|
||||
var queryMethod = new QueryMethod(method, metadata, factory, DefaultParameters::new);
|
||||
|
||||
assertThat(queryMethod.isPageQuery()).isFalse();
|
||||
assertThat(queryMethod.isScrollQuery()).isTrue();
|
||||
@@ -114,7 +116,7 @@ class QueryMethodUnitTests {
|
||||
@Test // GH-2151
|
||||
void supportsReactiveCursorQueries() throws Exception {
|
||||
var method = SampleRepository.class.getMethod("reactiveCursorWindow", ScrollPosition.class);
|
||||
var queryMethod = new QueryMethod(method, metadata, factory);
|
||||
var queryMethod = new QueryMethod(method, metadata, factory, DefaultParameters::new);
|
||||
assertThat(queryMethod.isPageQuery()).isFalse();
|
||||
|
||||
assertThat(queryMethod.isScrollQuery()).isTrue();
|
||||
@@ -125,14 +127,16 @@ class QueryMethodUnitTests {
|
||||
void rejectsInvalidReactiveCursorQueries() throws Exception {
|
||||
var method = SampleRepository.class.getMethod("invalidReactiveCursorWindow", ScrollPosition.class);
|
||||
|
||||
assertThatIllegalStateException().isThrownBy(() -> new QueryMethod(method, metadata, factory));
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> new QueryMethod(method, metadata, factory, DefaultParameters::new));
|
||||
}
|
||||
|
||||
@Test // GH-2151
|
||||
void rejectsCursorWindowMethodWithoutPageable() throws Exception {
|
||||
var method = SampleRepository.class.getMethod("cursorWindowWithoutScrollPosition");
|
||||
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new QueryMethod(method, metadata, factory));
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new QueryMethod(method, metadata, factory, DefaultParameters::new));
|
||||
}
|
||||
|
||||
@Test // GH-2151
|
||||
@@ -140,14 +144,15 @@ class QueryMethodUnitTests {
|
||||
|
||||
var method = SampleRepository.class.getMethod("cursorWindowMethodWithInvalidReturnType", ScrollPosition.class);
|
||||
|
||||
assertThatIllegalStateException().isThrownBy(() -> new QueryMethod(method, metadata, factory));
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> new QueryMethod(method, metadata, factory, DefaultParameters::new));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-171
|
||||
void detectsAnEntityBeingReturned() throws Exception {
|
||||
|
||||
var method = SampleRepository.class.getMethod("returnsEntitySubclass");
|
||||
var queryMethod = new QueryMethod(method, metadata, factory);
|
||||
var queryMethod = new QueryMethod(method, metadata, factory, DefaultParameters::new);
|
||||
|
||||
assertThat(queryMethod.isQueryForEntity()).isTrue();
|
||||
}
|
||||
@@ -156,7 +161,7 @@ class QueryMethodUnitTests {
|
||||
void detectsNonEntityBeingReturned() throws Exception {
|
||||
|
||||
var method = SampleRepository.class.getMethod("returnsProjection");
|
||||
var queryMethod = new QueryMethod(method, metadata, factory);
|
||||
var queryMethod = new QueryMethod(method, metadata, factory, DefaultParameters::new);
|
||||
|
||||
assertThat(queryMethod.isQueryForEntity()).isFalse();
|
||||
}
|
||||
@@ -166,7 +171,7 @@ class QueryMethodUnitTests {
|
||||
|
||||
RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(SampleRepository.class);
|
||||
var method = SampleRepository.class.getMethod("sliceOfUsers");
|
||||
var queryMethod = new QueryMethod(method, repositoryMetadata, factory);
|
||||
var queryMethod = new QueryMethod(method, repositoryMetadata, factory, DefaultParameters::new);
|
||||
|
||||
assertThat(queryMethod.isSliceQuery()).isTrue();
|
||||
assertThat(queryMethod.isCollectionQuery()).isFalse();
|
||||
@@ -179,7 +184,8 @@ class QueryMethodUnitTests {
|
||||
RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(SampleRepository.class);
|
||||
var method = SampleRepository.class.getMethod("arrayOfUsers");
|
||||
|
||||
assertThat(new QueryMethod(method, repositoryMetadata, factory).isCollectionQuery()).isTrue();
|
||||
assertThat(new QueryMethod(method, repositoryMetadata, factory, DefaultParameters::new).isCollectionQuery())
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-650
|
||||
@@ -188,7 +194,7 @@ class QueryMethodUnitTests {
|
||||
RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(SampleRepository.class);
|
||||
var method = SampleRepository.class.getMethod("streaming");
|
||||
|
||||
assertThat(new QueryMethod(method, repositoryMetadata, factory).isStreamQuery()).isTrue();
|
||||
assertThat(new QueryMethod(method, repositoryMetadata, factory, DefaultParameters::new).isStreamQuery()).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-650
|
||||
@@ -197,7 +203,7 @@ class QueryMethodUnitTests {
|
||||
RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(SampleRepository.class);
|
||||
var method = SampleRepository.class.getMethod("streaming", Pageable.class);
|
||||
|
||||
assertThat(new QueryMethod(method, repositoryMetadata, factory).isStreamQuery()).isTrue();
|
||||
assertThat(new QueryMethod(method, repositoryMetadata, factory, DefaultParameters::new).isStreamQuery()).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-716
|
||||
@@ -206,7 +212,8 @@ class QueryMethodUnitTests {
|
||||
RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(SampleRepository.class);
|
||||
var method = SampleRepository.class.getMethod("returnsCompletableFutureForSingleEntity");
|
||||
|
||||
assertThat(new QueryMethod(method, repositoryMetadata, factory).isCollectionQuery()).isFalse();
|
||||
assertThat(new QueryMethod(method, repositoryMetadata, factory, DefaultParameters::new).isCollectionQuery())
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-716
|
||||
@@ -215,7 +222,8 @@ class QueryMethodUnitTests {
|
||||
RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(SampleRepository.class);
|
||||
var method = SampleRepository.class.getMethod("returnsCompletableFutureForEntityCollection");
|
||||
|
||||
assertThat(new QueryMethod(method, repositoryMetadata, factory).isCollectionQuery()).isTrue();
|
||||
assertThat(new QueryMethod(method, repositoryMetadata, factory, DefaultParameters::new).isCollectionQuery())
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-716
|
||||
@@ -224,7 +232,8 @@ class QueryMethodUnitTests {
|
||||
RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(SampleRepository.class);
|
||||
var method = SampleRepository.class.getMethod("returnsFutureForSingleEntity");
|
||||
|
||||
assertThat(new QueryMethod(method, repositoryMetadata, factory).isCollectionQuery()).isFalse();
|
||||
assertThat(new QueryMethod(method, repositoryMetadata, factory, DefaultParameters::new).isCollectionQuery())
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-716
|
||||
@@ -233,7 +242,8 @@ class QueryMethodUnitTests {
|
||||
RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(SampleRepository.class);
|
||||
var method = SampleRepository.class.getMethod("returnsFutureForEntityCollection");
|
||||
|
||||
assertThat(new QueryMethod(method, repositoryMetadata, factory).isCollectionQuery()).isTrue();
|
||||
assertThat(new QueryMethod(method, repositoryMetadata, factory, DefaultParameters::new).isCollectionQuery())
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -245,7 +255,8 @@ class QueryMethodUnitTests {
|
||||
RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(SampleRepository.class);
|
||||
var method = SampleRepository.class.getMethod("returnsSeq");
|
||||
|
||||
assertThat(new QueryMethod(method, repositoryMetadata, factory).isCollectionQuery()).isTrue();
|
||||
assertThat(new QueryMethod(method, repositoryMetadata, factory, DefaultParameters::new).isCollectionQuery())
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -257,7 +268,8 @@ class QueryMethodUnitTests {
|
||||
RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(SampleRepository.class);
|
||||
var method = SampleRepository.class.getMethod("returnsFutureOfSeq");
|
||||
|
||||
assertThat(new QueryMethod(method, repositoryMetadata, factory).isCollectionQuery()).isTrue();
|
||||
assertThat(new QueryMethod(method, repositoryMetadata, factory, DefaultParameters::new).isCollectionQuery())
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,7 +281,8 @@ class QueryMethodUnitTests {
|
||||
RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(SampleRepository.class);
|
||||
var method = SampleRepository.class.getMethod("returnsFutureOfOption");
|
||||
|
||||
assertThat(new QueryMethod(method, repositoryMetadata, factory).isCollectionQuery()).isFalse();
|
||||
assertThat(new QueryMethod(method, repositoryMetadata, factory, DefaultParameters::new).isCollectionQuery())
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1005
|
||||
@@ -278,7 +291,8 @@ class QueryMethodUnitTests {
|
||||
RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(SampleRepository.class);
|
||||
var method = SampleRepository.class.getMethod("returnsSeq", Pageable.class);
|
||||
|
||||
assertThat(new QueryMethod(method, repositoryMetadata, factory).isCollectionQuery()).isTrue();
|
||||
assertThat(new QueryMethod(method, repositoryMetadata, factory, DefaultParameters::new).isCollectionQuery())
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1300
|
||||
@@ -287,7 +301,7 @@ class QueryMethodUnitTests {
|
||||
var metadata = AbstractRepositoryMetadata.getMetadata(ContainerRepository.class);
|
||||
var method = ContainerRepository.class.getMethod("someMethod");
|
||||
|
||||
assertThat(new QueryMethod(method, metadata, factory).isCollectionQuery()).isFalse();
|
||||
assertThat(new QueryMethod(method, metadata, factory, DefaultParameters::new).isCollectionQuery()).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1762
|
||||
@@ -296,7 +310,7 @@ class QueryMethodUnitTests {
|
||||
RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(SampleRepository.class);
|
||||
var method = SampleRepository.class.getMethod("reactiveSlice");
|
||||
|
||||
var queryMethod = new QueryMethod(method, repositoryMetadata, factory);
|
||||
var queryMethod = new QueryMethod(method, repositoryMetadata, factory, DefaultParameters::new);
|
||||
var returnedType = queryMethod.getResultProcessor().getReturnedType();
|
||||
assertThat(queryMethod.isSliceQuery()).isTrue();
|
||||
assertThat(returnedType.getTypeToRead()).isEqualTo(User.class);
|
||||
@@ -307,7 +321,7 @@ class QueryMethodUnitTests {
|
||||
void considersEclipseCollectionCollectionQuery() throws Exception {
|
||||
|
||||
var method = SampleRepository.class.getMethod("returnsEclipseCollection");
|
||||
var queryMethod = new QueryMethod(method, metadata, factory);
|
||||
var queryMethod = new QueryMethod(method, metadata, factory, DefaultParameters::new);
|
||||
|
||||
assertThat(queryMethod.isCollectionQuery()).isTrue();
|
||||
}
|
||||
@@ -317,7 +331,8 @@ class QueryMethodUnitTests {
|
||||
|
||||
var method = SampleRepository.class.getMethod("pageableAndSort", Pageable.class, Sort.class);
|
||||
|
||||
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> new QueryMethod(method, metadata, factory));
|
||||
assertThatExceptionOfType(IllegalStateException.class)
|
||||
.isThrownBy(() -> new QueryMethod(method, metadata, factory, DefaultParameters::new));
|
||||
}
|
||||
|
||||
@Test // GH-2827
|
||||
@@ -325,7 +340,8 @@ class QueryMethodUnitTests {
|
||||
|
||||
var method = SampleRepository.class.getMethod("pageableAndLimit", Pageable.class, Limit.class);
|
||||
|
||||
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> new QueryMethod(method, metadata, factory));
|
||||
assertThatExceptionOfType(IllegalStateException.class)
|
||||
.isThrownBy(() -> new QueryMethod(method, metadata, factory, DefaultParameters::new));
|
||||
}
|
||||
|
||||
@Test // GH-2827
|
||||
@@ -333,7 +349,7 @@ class QueryMethodUnitTests {
|
||||
|
||||
var method = SampleRepository.class.getMethod("sortAndLimit", Sort.class, Limit.class);
|
||||
|
||||
new QueryMethod(method, metadata, factory);
|
||||
new QueryMethod(method, metadata, factory, DefaultParameters::new);
|
||||
}
|
||||
|
||||
@Test // GH-2827
|
||||
@@ -341,7 +357,7 @@ class QueryMethodUnitTests {
|
||||
|
||||
var method = SampleRepository.class.getMethod("scrollPositionAndLimit", ScrollPosition.class, Limit.class);
|
||||
|
||||
new QueryMethod(method, metadata, factory);
|
||||
new QueryMethod(method, metadata, factory, DefaultParameters::new);
|
||||
}
|
||||
|
||||
@Test // GH-2827
|
||||
@@ -349,7 +365,7 @@ class QueryMethodUnitTests {
|
||||
|
||||
var method = SampleRepository.class.getMethod("findTop5By", Limit.class);
|
||||
|
||||
new QueryMethod(method, metadata, factory);
|
||||
new QueryMethod(method, metadata, factory, DefaultParameters::new);
|
||||
}
|
||||
|
||||
@Test // GH-2827
|
||||
@@ -357,7 +373,7 @@ class QueryMethodUnitTests {
|
||||
|
||||
var method = SampleRepository.class.getMethod("findTop5By", Pageable.class);
|
||||
|
||||
new QueryMethod(method, metadata, factory);
|
||||
new QueryMethod(method, metadata, factory, DefaultParameters::new);
|
||||
}
|
||||
|
||||
@Test // GH-2827
|
||||
@@ -365,7 +381,7 @@ class QueryMethodUnitTests {
|
||||
|
||||
var method = SampleRepository.class.getMethod("scrollPositionAndSort", ScrollPosition.class, Sort.class);
|
||||
|
||||
new QueryMethod(method, metadata, factory);
|
||||
new QueryMethod(method, metadata, factory, DefaultParameters::new);
|
||||
}
|
||||
|
||||
@TestFactory // GH-2869
|
||||
@@ -373,10 +389,7 @@ class QueryMethodUnitTests {
|
||||
throws Exception {
|
||||
|
||||
var metadata = AbstractRepositoryMetadata.getMetadata(StreamableAggregateRepository.class);
|
||||
var stream = Stream.of(
|
||||
Map.entry("findBy", false),
|
||||
Map.entry("findSubTypeBy", false),
|
||||
Map.entry("findAllBy", true),
|
||||
var stream = Stream.of(Map.entry("findBy", false), Map.entry("findSubTypeBy", false), Map.entry("findAllBy", true),
|
||||
Map.entry("findOptionalBy", false));
|
||||
|
||||
return DynamicTest.stream(stream, //
|
||||
@@ -384,7 +397,7 @@ class QueryMethodUnitTests {
|
||||
it -> {
|
||||
|
||||
var method = StreamableAggregateRepository.class.getMethod(it.getKey());
|
||||
var queryMethod = new QueryMethod(method, metadata, factory);
|
||||
var queryMethod = new QueryMethod(method, metadata, factory, DefaultParameters::new);
|
||||
|
||||
assertThat(queryMethod.isCollectionQuery()).isEqualTo(it.getValue());
|
||||
});
|
||||
@@ -394,7 +407,7 @@ class QueryMethodUnitTests {
|
||||
void considersSearchResults() throws NoSuchMethodException {
|
||||
|
||||
var method = SampleRepository.class.getMethod("searchTop5By");
|
||||
QueryMethod queryMethod = new QueryMethod(method, metadata, factory);
|
||||
QueryMethod queryMethod = new QueryMethod(method, metadata, factory, DefaultParameters::new);
|
||||
|
||||
assertThat(queryMethod.isSearchQuery()).isTrue();
|
||||
}
|
||||
@@ -403,7 +416,7 @@ class QueryMethodUnitTests {
|
||||
void considersSearchResult() throws NoSuchMethodException {
|
||||
|
||||
var method = SampleRepository.class.getMethod("searchListTop5By");
|
||||
QueryMethod queryMethod = new QueryMethod(method, metadata, factory);
|
||||
QueryMethod queryMethod = new QueryMethod(method, metadata, factory, DefaultParameters::new);
|
||||
|
||||
assertThat(queryMethod.isSearchQuery()).isTrue();
|
||||
}
|
||||
|
||||
@@ -344,7 +344,7 @@ class ResultProcessorUnitTests {
|
||||
|
||||
var method = SampleRepository.class.getMethod(name, parameters);
|
||||
return new QueryMethod(method, new DefaultRepositoryMetadata(SampleRepository.class),
|
||||
new SpelAwareProxyProjectionFactory());
|
||||
new SpelAwareProxyProjectionFactory(), DefaultParameters::new);
|
||||
}
|
||||
|
||||
interface SampleRepository extends Repository<Sample, Long> {
|
||||
|
||||
@@ -194,7 +194,7 @@ class ReturnedTypeUnitTests {
|
||||
|
||||
var method = SampleRepository.class.getMethod(name, parameters);
|
||||
return new QueryMethod(method, new DefaultRepositoryMetadata(SampleRepository.class),
|
||||
new SpelAwareProxyProjectionFactory());
|
||||
new SpelAwareProxyProjectionFactory(), DefaultParameters::new);
|
||||
}
|
||||
|
||||
interface SampleRepository extends Repository<Sample, Long> {
|
||||
|
||||
@@ -73,14 +73,12 @@ public class KotlinReflectionUtilsUnitTests {
|
||||
assertThat(KotlinReflectionUtils.isSupportedKotlinClass(TypeCreatingSyntheticClassKt.class)).isFalse();
|
||||
}
|
||||
|
||||
void runTest(String testName)
|
||||
throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException {
|
||||
void runTest(String testName) throws ReflectiveOperationException {
|
||||
|
||||
var classLoader = new KotlinExcludingURLClassLoader(
|
||||
((URLClassLoader) getClass().getClassLoader()).getURLs());
|
||||
var classLoader = new KotlinExcludingURLClassLoader(((URLClassLoader) getClass().getClassLoader()).getURLs());
|
||||
var testClass = ClassUtils.forName(getClass().getName(), classLoader);
|
||||
|
||||
ReflectionUtils.invokeMethod(testClass.getMethod(testName), testClass.newInstance());
|
||||
ReflectionUtils.invokeMethod(testClass.getMethod(testName), testClass.getConstructor().newInstance());
|
||||
}
|
||||
|
||||
static class KotlinExcludingURLClassLoader extends URLClassLoader {
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
class NullableUtilsUnitTests {
|
||||
|
||||
@Test // DATACMNS-1154
|
||||
|
||||
@@ -22,11 +22,11 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.projection.ProjectionFactory;
|
||||
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@@ -224,7 +224,8 @@ class JsonProjectingMethodInterceptorFactoryUnitTests {
|
||||
|
||||
// Not available in the payload
|
||||
@JsonPath("$.lastname")
|
||||
@Nullable String getLastname();
|
||||
@Nullable
|
||||
String getLastname();
|
||||
|
||||
// First one not available in the payload
|
||||
@JsonPath({ "$.lastname", "$.firstname" })
|
||||
|
||||
Reference in New Issue
Block a user