Browse Source

Polishing.

Move off deprecated API in tests.

See #3305
Original pull request: #3307
issue/3.5.x/3441
Mark Paluch 8 months ago
parent
commit
c97d75c5ac
No known key found for this signature in database
GPG Key ID: 55BC6374BAA9D973
  1. 6
      src/test/java/org/springframework/data/auditing/config/AuditingBeanDefinitionRegistrarSupportUnitTests.java
  2. 3
      src/test/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactoryTests.java
  3. 3
      src/test/java/org/springframework/data/projection/ProxyProjectionFactoryUnitTests.java
  4. 10
      src/test/java/org/springframework/data/repository/config/AnnotationRepositoryConfigurationSourceUnitTests.java
  5. 13
      src/test/java/org/springframework/data/repository/config/RepositoryBeanDefinitionRegistrarSupportUnitTests.java
  6. 4
      src/test/java/org/springframework/data/repository/config/RepositoryConfigurationExtensionSupportUnitTests.java
  7. 91
      src/test/java/org/springframework/data/repository/query/QueryMethodUnitTests.java
  8. 2
      src/test/java/org/springframework/data/repository/query/ResultProcessorUnitTests.java
  9. 2
      src/test/java/org/springframework/data/repository/query/ReturnedTypeUnitTests.java
  10. 8
      src/test/java/org/springframework/data/util/KotlinReflectionUtilsUnitTests.java
  11. 1
      src/test/java/org/springframework/data/util/NullableUtilsUnitTests.java
  12. 3
      src/test/java/org/springframework/data/web/JsonProjectingMethodInterceptorFactoryUnitTests.java

6
src/test/java/org/springframework/data/auditing/config/AuditingBeanDefinitionRegistrarSupportUnitTests.java

@ -25,10 +25,10 @@ import org.junit.jupiter.api.Test; @@ -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 { @@ -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 { @@ -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));

3
src/test/java/org/springframework/data/mapping/model/ClassGeneratingPropertyAccessorFactoryTests.java

@ -68,7 +68,8 @@ public class ClassGeneratingPropertyAccessorFactoryTests { @@ -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;
}

3
src/test/java/org/springframework/data/projection/ProxyProjectionFactoryUnitTests.java

@ -395,7 +395,8 @@ class ProxyProjectionFactoryUnitTests { @@ -395,7 +395,8 @@ class ProxyProjectionFactoryUnitTests {
interface CustomerProjectionWithNullables {
@Nullable String getFirstname();
@Nullable
String getFirstname();
String getLastname();
}

10
src/test/java/org/springframework/data/repository/config/AnnotationRepositoryConfigurationSourceUnitTests.java

@ -34,7 +34,6 @@ import org.springframework.core.env.StandardEnvironment; @@ -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 { @@ -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 { @@ -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 { @@ -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);
@ -197,7 +195,7 @@ class AnnotationRepositoryConfigurationSourceUnitTests { @@ -197,7 +195,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);
}

13
src/test/java/org/springframework/data/repository/config/RepositoryBeanDefinitionRegistrarSupportUnitTests.java

@ -35,7 +35,6 @@ import org.springframework.context.annotation.FilterType; @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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();

4
src/test/java/org/springframework/data/repository/config/RepositoryConfigurationExtensionSupportUnitTests.java

@ -23,6 +23,7 @@ import java.util.Collection; @@ -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; @@ -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 { @@ -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);

91
src/test/java/org/springframework/data/repository/query/QueryMethodUnitTests.java

@ -68,33 +68,35 @@ class QueryMethodUnitTests { @@ -68,33 +68,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();
}
@ -102,7 +104,7 @@ class QueryMethodUnitTests { @@ -102,7 +104,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();
@ -112,7 +114,7 @@ class QueryMethodUnitTests { @@ -112,7 +114,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();
@ -123,14 +125,16 @@ class QueryMethodUnitTests { @@ -123,14 +125,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
@ -138,14 +142,15 @@ class QueryMethodUnitTests { @@ -138,14 +142,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();
}
@ -154,7 +159,7 @@ class QueryMethodUnitTests { @@ -154,7 +159,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();
}
@ -164,7 +169,7 @@ class QueryMethodUnitTests { @@ -164,7 +169,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();
@ -177,7 +182,8 @@ class QueryMethodUnitTests { @@ -177,7 +182,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
@ -186,7 +192,7 @@ class QueryMethodUnitTests { @@ -186,7 +192,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
@ -195,7 +201,7 @@ class QueryMethodUnitTests { @@ -195,7 +201,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
@ -204,7 +210,8 @@ class QueryMethodUnitTests { @@ -204,7 +210,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
@ -213,7 +220,8 @@ class QueryMethodUnitTests { @@ -213,7 +220,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
@ -222,7 +230,8 @@ class QueryMethodUnitTests { @@ -222,7 +230,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
@ -231,7 +240,8 @@ class QueryMethodUnitTests { @@ -231,7 +240,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();
}
/**
@ -243,7 +253,8 @@ class QueryMethodUnitTests { @@ -243,7 +253,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();
}
/**
@ -255,7 +266,8 @@ class QueryMethodUnitTests { @@ -255,7 +266,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();
}
/**
@ -267,7 +279,8 @@ class QueryMethodUnitTests { @@ -267,7 +279,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
@ -276,7 +289,8 @@ class QueryMethodUnitTests { @@ -276,7 +289,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
@ -285,7 +299,7 @@ class QueryMethodUnitTests { @@ -285,7 +299,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
@ -294,7 +308,7 @@ class QueryMethodUnitTests { @@ -294,7 +308,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);
@ -305,7 +319,7 @@ class QueryMethodUnitTests { @@ -305,7 +319,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();
}
@ -315,7 +329,8 @@ class QueryMethodUnitTests { @@ -315,7 +329,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
@ -323,7 +338,8 @@ class QueryMethodUnitTests { @@ -323,7 +338,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
@ -331,7 +347,7 @@ class QueryMethodUnitTests { @@ -331,7 +347,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
@ -339,7 +355,7 @@ class QueryMethodUnitTests { @@ -339,7 +355,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
@ -347,7 +363,7 @@ class QueryMethodUnitTests { @@ -347,7 +363,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
@ -355,7 +371,7 @@ class QueryMethodUnitTests { @@ -355,7 +371,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
@ -363,7 +379,7 @@ class QueryMethodUnitTests { @@ -363,7 +379,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
@ -371,10 +387,7 @@ class QueryMethodUnitTests { @@ -371,10 +387,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, //
@ -382,7 +395,7 @@ class QueryMethodUnitTests { @@ -382,7 +395,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());
});

2
src/test/java/org/springframework/data/repository/query/ResultProcessorUnitTests.java

@ -344,7 +344,7 @@ class ResultProcessorUnitTests { @@ -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> {

2
src/test/java/org/springframework/data/repository/query/ReturnedTypeUnitTests.java

@ -194,7 +194,7 @@ class ReturnedTypeUnitTests { @@ -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> {

8
src/test/java/org/springframework/data/util/KotlinReflectionUtilsUnitTests.java

@ -73,14 +73,12 @@ public class KotlinReflectionUtilsUnitTests { @@ -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 {

1
src/test/java/org/springframework/data/util/NullableUtilsUnitTests.java

@ -34,6 +34,7 @@ import org.springframework.util.ReflectionUtils; @@ -34,6 +34,7 @@ import org.springframework.util.ReflectionUtils;
* @author Mark Paluch
* @author Christoph Strobl
*/
@SuppressWarnings("deprecation")
class NullableUtilsUnitTests {
@Test // DATACMNS-1154

3
src/test/java/org/springframework/data/web/JsonProjectingMethodInterceptorFactoryUnitTests.java

@ -224,7 +224,8 @@ class JsonProjectingMethodInterceptorFactoryUnitTests { @@ -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" })

Loading…
Cancel
Save