diff --git a/src/main/java/org/springframework/data/auditing/AuditingHandler.java b/src/main/java/org/springframework/data/auditing/AuditingHandler.java index 9e4e5b1b7..220e24270 100644 --- a/src/main/java/org/springframework/data/auditing/AuditingHandler.java +++ b/src/main/java/org/springframework/data/auditing/AuditingHandler.java @@ -19,11 +19,9 @@ import java.util.Optional; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.beans.factory.InitializingBean; import org.springframework.data.domain.AuditorAware; -import org.springframework.data.mapping.PersistentEntity; -import org.springframework.data.mapping.PersistentProperty; -import org.springframework.data.mapping.context.MappingContext; import org.springframework.data.mapping.context.PersistentEntities; import org.springframework.util.Assert; @@ -40,20 +38,6 @@ public class AuditingHandler extends AuditingHandlerSupport implements Initializ private Optional> auditorAware; - /** - * Creates a new {@link AuditableBeanWrapper} using the given {@link MappingContext} when looking up auditing metadata - * via reflection. - * - * @param mappingContext must not be {@literal null}. - * @since 1.8 - * @deprecated use {@link AuditingHandler(PersistentEntities)} instead. - */ - @Deprecated - public AuditingHandler( - MappingContext, ? extends PersistentProperty> mappingContext) { - this(PersistentEntities.of(mappingContext)); - } - /** * Creates a new {@link AuditableBeanWrapper} using the given {@link PersistentEntities} when looking up auditing * metadata via reflection. diff --git a/src/main/java/org/springframework/data/auditing/IsNewAwareAuditingHandler.java b/src/main/java/org/springframework/data/auditing/IsNewAwareAuditingHandler.java index 0c5901d80..b958fcc88 100644 --- a/src/main/java/org/springframework/data/auditing/IsNewAwareAuditingHandler.java +++ b/src/main/java/org/springframework/data/auditing/IsNewAwareAuditingHandler.java @@ -35,19 +35,6 @@ public class IsNewAwareAuditingHandler extends AuditingHandler { private final PersistentEntities entities; - /** - * Creates a new {@link IsNewAwareAuditingHandler} for the given {@link MappingContext}. - * - * @param mappingContext must not be {@literal null}. - * @since 1.8 - * @deprecated use {@link IsNewAwareAuditingHandler(PersistentEntities)} instead. - */ - @Deprecated - public IsNewAwareAuditingHandler( - MappingContext, ? extends PersistentProperty> mappingContext) { - this(PersistentEntities.of(mappingContext)); - } - /** * Creates a new {@link IsNewAwareAuditingHandler} for the given {@link MappingContext}. * diff --git a/src/main/java/org/springframework/data/mapping/PersistentProperty.java b/src/main/java/org/springframework/data/mapping/PersistentProperty.java index 99cc367d9..af15f638e 100644 --- a/src/main/java/org/springframework/data/mapping/PersistentProperty.java +++ b/src/main/java/org/springframework/data/mapping/PersistentProperty.java @@ -64,17 +64,6 @@ public interface PersistentProperty

> { */ TypeInformation getTypeInformation(); - /** - * Returns the {@link TypeInformation} if the property references a {@link PersistentEntity}. Will return - * {@literal null} in case it refers to a simple type. Will return {@link Collection}'s component type or the - * {@link Map}'s value type transparently. - * - * @return - * @deprecated since 2.6 for removal in 3.0. Use {@link #getPersistentEntityTypeInformation()} instead. - */ - @Deprecated - Iterable> getPersistentEntityTypes(); - /** * Returns the detected {@link TypeInformation TypeInformations} if the property references a {@link PersistentEntity}. * Will return an {@literal empty} {@link Iterable} in case it refers to a simple type. Will return the {@link Collection}'s diff --git a/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java b/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java index b7361896b..baa8999f8 100644 --- a/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java +++ b/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java @@ -158,15 +158,6 @@ public abstract class AbstractPersistentProperty

return information; } - /* - * (non-Javadoc) - * @see org.springframework.data.mapping.PersistentProperty#getPersistentEntityTypes() - */ - @Override - public Iterable> getPersistentEntityTypes() { - return getPersistentEntityTypeInformation(); - } - /* * (non-Javadoc) * @see org.springframework.data.mapping.PersistentProperty#getPersistentEntityTypeInformation() diff --git a/src/main/java/org/springframework/data/mapping/model/InstantiationAwarePropertyAccessor.java b/src/main/java/org/springframework/data/mapping/model/InstantiationAwarePropertyAccessor.java index 014e9597f..cd1c65ab2 100644 --- a/src/main/java/org/springframework/data/mapping/model/InstantiationAwarePropertyAccessor.java +++ b/src/main/java/org/springframework/data/mapping/model/InstantiationAwarePropertyAccessor.java @@ -46,26 +46,6 @@ public class InstantiationAwarePropertyAccessor implements PersistentProperty private T bean; - /** - * Creates an {@link InstantiationAwarePropertyAccessor} using the given delegate {@link PersistentPropertyAccessor} - * and {@link EntityInstantiators}. - * - * @param delegate must not be {@literal null}. - * @param instantiators must not be {@literal null}. - * @deprecated since 2.4. Using this constructor allows only setting a single property as - * {@link PersistentPropertyAccessor} holds a reference to the initial bean state. - */ - @Deprecated - public InstantiationAwarePropertyAccessor(PersistentPropertyAccessor delegate, EntityInstantiators instantiators) { - - Assert.notNull(delegate, "Delegate PersistentPropertyAccessor must not be null!"); - Assert.notNull(instantiators, "EntityInstantiators must not be null!"); - - this.instantiators = instantiators; - this.delegateFunction = t -> delegate; - this.bean = delegate.getBean(); - } - /** * Creates an {@link InstantiationAwarePropertyAccessor} using the given delegate {@code accessorFunction} and * {@link EntityInstantiators}. {@code accessorFunction} is used to obtain a new {@link PersistentPropertyAccessor} diff --git a/src/main/java/org/springframework/data/repository/cdi/CdiRepositoryBean.java b/src/main/java/org/springframework/data/repository/cdi/CdiRepositoryBean.java index 0ecefb75c..169da4e86 100644 --- a/src/main/java/org/springframework/data/repository/cdi/CdiRepositoryBean.java +++ b/src/main/java/org/springframework/data/repository/cdi/CdiRepositoryBean.java @@ -322,16 +322,7 @@ public abstract class CdiRepositoryBean implements Bean, PassivationCapabl * @param repositoryType will never be {@literal null}. * @return */ - protected T create(CreationalContext creationalContext, Class repositoryType) { - - CdiRepositoryConfiguration cdiRepositoryConfiguration = lookupConfiguration(beanManager, qualifiers); - - Optional> customImplementationBean = getCustomImplementationBean(repositoryType, - cdiRepositoryConfiguration); - Optional customImplementation = customImplementationBean.map(this::getDependencyInstance); - - return create(creationalContext, repositoryType, customImplementation); - } + protected abstract T create(CreationalContext creationalContext, Class repositoryType); /** * Creates the actual component instance given a {@link RepositoryFactorySupport repository factory supplier} and the @@ -417,24 +408,6 @@ public abstract class CdiRepositoryBean implements Bean, PassivationCapabl Arrays.asList(repositoryType.getInterfaces())))); } - /** - * Creates the actual component instance. - * - * @param creationalContext will never be {@literal null}. - * @param repositoryType will never be {@literal null}. - * @param customImplementation can be {@literal null}. - * @return - * @deprecated since 2.1, override {@link #create(CreationalContext, Class)} in which you create a repository factory - * and call {@link #create(RepositoryFactorySupport, Class, RepositoryFragments)}. - */ - @Deprecated - protected T create(CreationalContext creationalContext, Class repositoryType, - Optional customImplementation) { - throw new UnsupportedOperationException( - "You have to implement create(CreationalContext, Class, Optional) " - + "in order to use custom repository implementations"); - } - /** * Looks up an instance of a {@link CdiRepositoryConfiguration}. In case the instance cannot be found within the CDI * scope, a default configuration is used. diff --git a/src/main/java/org/springframework/data/repository/query/ParameterAccessor.java b/src/main/java/org/springframework/data/repository/query/ParameterAccessor.java index b4bd87a62..e7ddc9105 100644 --- a/src/main/java/org/springframework/data/repository/query/ParameterAccessor.java +++ b/src/main/java/org/springframework/data/repository/query/ParameterAccessor.java @@ -16,7 +16,6 @@ package org.springframework.data.repository.query; import java.util.Iterator; -import java.util.Optional; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; @@ -46,16 +45,6 @@ public interface ParameterAccessor extends Iterable { */ Sort getSort(); - /** - * Returns the dynamic projection type to be used when executing the query or {@literal null} if none is defined. - * - * @return - * @since 1.12 - * @deprecated use {@link #findDynamicProjection()} instead. - */ - @Deprecated - Optional> getDynamicProjection(); - /** * Returns the dynamic projection type to be used when executing the query or {@literal null} if none is defined. * diff --git a/src/main/java/org/springframework/data/repository/query/ParametersParameterAccessor.java b/src/main/java/org/springframework/data/repository/query/ParametersParameterAccessor.java index 98f04fb9a..c1ccbe5c6 100644 --- a/src/main/java/org/springframework/data/repository/query/ParametersParameterAccessor.java +++ b/src/main/java/org/springframework/data/repository/query/ParametersParameterAccessor.java @@ -16,7 +16,6 @@ package org.springframework.data.repository.query; import java.util.Iterator; -import java.util.Optional; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; @@ -128,18 +127,6 @@ public class ParametersParameterAccessor implements ParameterAccessor { return Sort.unsorted(); } - /** - * Returns the dynamic projection type if available, {@literal null} otherwise. - * - * @return - */ - public Optional> getDynamicProjection() { - - return Optional.ofNullable(parameters.hasDynamicProjection() // - ? (Class) values[parameters.getDynamicProjectionIndex()] // - : null); - } - /** * Returns the dynamic projection type if available, {@literal null} otherwise. * diff --git a/src/main/java/org/springframework/data/repository/support/PageableExecutionUtils.java b/src/main/java/org/springframework/data/repository/support/PageableExecutionUtils.java deleted file mode 100644 index 075ee3efa..000000000 --- a/src/main/java/org/springframework/data/repository/support/PageableExecutionUtils.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2016-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.repository.support; - -import java.util.List; -import java.util.function.LongSupplier; - -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; - -/** - * Support for query execution using {@link Pageable}. Using {@link PageableExecutionUtils} assumes that data queries - * are cheaper than {@code COUNT} queries and so some cases can take advantage of optimizations. - * - * @author Mark Paluch - * @author Oliver Gierke - * @author Christoph Strobl - * @author Jens Schauder - * @since 1.13 - * @deprecated since 2.4. Use {@link org.springframework.data.support.PageableExecutionUtils} instead - */ -@Deprecated -public abstract class PageableExecutionUtils { - - private PageableExecutionUtils() {} - - /** - * Constructs a {@link Page} based on the given {@code content}, {@link Pageable} and {@link LongSupplier} applying - * optimizations. The construction of {@link Page} omits a count query if the total can be determined based on the - * result size and {@link Pageable}. - * - * @param content result of a query with applied {@link Pageable}. The list must not be {@literal null} and must - * contain up to {@link Pageable#getPageSize()} items. - * @param pageable must not be {@literal null}. - * @param totalSupplier must not be {@literal null}. - * @return the {@link Page} for {@link List content} and a total size. - */ - public static Page getPage(List content, Pageable pageable, LongSupplier totalSupplier) { - return org.springframework.data.support.PageableExecutionUtils.getPage(content, pageable, totalSupplier); - } -} diff --git a/src/main/java/org/springframework/data/repository/util/NullableWrapper.java b/src/main/java/org/springframework/data/repository/util/NullableWrapper.java deleted file mode 100644 index da01954d1..000000000 --- a/src/main/java/org/springframework/data/repository/util/NullableWrapper.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2014-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.repository.util; - -import org.springframework.core.convert.converter.Converter; -import org.springframework.lang.Nullable; - -/** - * Simple value object to wrap a nullable delegate. Used to be able to write {@link Converter} implementations that - * convert {@literal null} into an object of some sort. - * - * @author Oliver Gierke - * @author Mark Paluch - * @since 1.8 - * @see QueryExecutionConverters - * @deprecated since 2.4, use {@link org.springframework.data.util.NullableWrapper} instead. - */ -@Deprecated -public class NullableWrapper extends org.springframework.data.util.NullableWrapper { - - /** - * Creates a new {@link NullableWrapper} for the given value. - * - * @param value can be {@literal null}. - */ - public NullableWrapper(@Nullable Object value) { - super(value); - } -} diff --git a/src/main/java/org/springframework/data/repository/util/ReactiveWrappers.java b/src/main/java/org/springframework/data/repository/util/ReactiveWrappers.java index fe2929fd5..7be194215 100644 --- a/src/main/java/org/springframework/data/repository/util/ReactiveWrappers.java +++ b/src/main/java/org/springframework/data/repository/util/ReactiveWrappers.java @@ -19,8 +19,6 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; import java.util.Optional; import org.springframework.core.ReactiveAdapter; @@ -220,39 +218,6 @@ public abstract class ReactiveWrappers { : findDescriptor(type).map(ReactiveTypeDescriptor::isMultiValue).orElse(false); } - /** - * Returns a collection of no-value wrapper types. - * - * @return a collection of no-value wrapper types. - * @deprecated not supported anymore. - */ - @Deprecated - public static Collection> getNoValueTypes() { - return Collections.emptyList(); - } - - /** - * Returns a collection of single-value wrapper types. - * - * @return a collection of single-value wrapper types. - * @deprecated not supported anymore. - */ - @Deprecated - public static Collection> getSingleValueTypes() { - return Collections.emptyList(); - } - - /** - * Returns a collection of multi-value wrapper types. - * - * @return a collection of multi-value wrapper types. - * @deprecated not supported anymore. - */ - @Deprecated - public static Collection> getMultiValueTypes() { - return Collections.emptyList(); - } - /** * Returns whether the given type is a reactive wrapper type. * diff --git a/src/main/java/org/springframework/data/util/Lazy.java b/src/main/java/org/springframework/data/util/Lazy.java index 954fa731d..410a602c9 100644 --- a/src/main/java/org/springframework/data/util/Lazy.java +++ b/src/main/java/org/springframework/data/util/Lazy.java @@ -46,10 +46,8 @@ public class Lazy implements Supplier { * Creates a new {@link Lazy} instance for the given supplier. * * @param supplier - * @deprecated prefer {@link Lazy#of(Supplier)}, to be turned private in 2.5. */ - @Deprecated - public Lazy(Supplier supplier) { + private Lazy(Supplier supplier) { this(supplier, null, false); } diff --git a/src/main/java/org/springframework/data/util/ReflectionUtils.java b/src/main/java/org/springframework/data/util/ReflectionUtils.java index 54a5062ae..8d778cce2 100644 --- a/src/main/java/org/springframework/data/util/ReflectionUtils.java +++ b/src/main/java/org/springframework/data/util/ReflectionUtils.java @@ -386,31 +386,6 @@ public final class ReflectionUtils { return true; } - /** - * Return {@literal true} if the specified class is a Kotlin one. - * - * @return {@literal true} if {@code type} is a Kotlin class. - * @since 2.0 - * @deprecated since 2.3, use {@link KotlinDetector#isKotlinType(Class)} instead. - */ - @Deprecated - public static boolean isKotlinClass(Class type) { - return KotlinDetector.isKotlinType(type); - } - - /** - * Return {@literal true} if the specified class is a supported Kotlin class. Currently supported are only regular - * Kotlin classes. Other class types (synthetic, SAM, lambdas) are not supported via reflection. - * - * @return {@literal true} if {@code type} is a supported Kotlin class. - * @since 2.0 - * @deprecated since 2.3, use {@link KotlinReflectionUtils#isSupportedKotlinClass(Class)} instead. - */ - @Deprecated - public static boolean isSupportedKotlinClass(Class type) { - return KotlinReflectionUtils.isSupportedKotlinClass(type); - } - /** * Returns {@literal} whether the given {@link MethodParameter} is nullable. Nullable parameters are reference types * and ones that are defined in Kotlin as such. @@ -424,7 +399,8 @@ public final class ReflectionUtils { return true; } - if (isSupportedKotlinClass(parameter.getDeclaringClass())) { + if (KotlinDetector.isKotlinPresent() + && KotlinReflectionUtils.isSupportedKotlinClass(parameter.getDeclaringClass())) { return KotlinReflectionUtils.isNullable(parameter); } diff --git a/src/main/java/org/springframework/data/web/PagedResourcesAssemblerArgumentResolver.java b/src/main/java/org/springframework/data/web/PagedResourcesAssemblerArgumentResolver.java index 248294f3a..489a1ff98 100644 --- a/src/main/java/org/springframework/data/web/PagedResourcesAssemblerArgumentResolver.java +++ b/src/main/java/org/springframework/data/web/PagedResourcesAssemblerArgumentResolver.java @@ -25,9 +25,7 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.core.MethodParameter; import org.springframework.core.log.LogMessage; import org.springframework.data.domain.Pageable; -import org.springframework.hateoas.server.MethodLinkBuilderFactory; import org.springframework.hateoas.server.core.MethodParameters; -import org.springframework.hateoas.server.mvc.WebMvcLinkBuilderFactory; import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; import org.springframework.web.bind.support.WebDataBinderFactory; @@ -53,21 +51,6 @@ public class PagedResourcesAssemblerArgumentResolver implements HandlerMethodArg private final HateoasPageableHandlerMethodArgumentResolver resolver; - /** - * Creates a new {@link PagedResourcesAssemblerArgumentResolver} using the given - * {@link PageableHandlerMethodArgumentResolver} and {@link MethodLinkBuilderFactory}. - * - * @param resolver can be {@literal null}. - * @param linkBuilderFactory can be {@literal null}, will be defaulted to a {@link WebMvcLinkBuilderFactory}. - * @deprecated since 2.5, 2.4.4, 2.3.7, to be removed in 3.0 - * @use {@link #PagedResourcesAssemblerArgumentResolver(HateoasPageableHandlerMethodArgumentResolver)} instead. - */ - @Deprecated - public PagedResourcesAssemblerArgumentResolver(HateoasPageableHandlerMethodArgumentResolver resolver, - @Nullable MethodLinkBuilderFactory linkBuilderFactory) { - this(resolver); - } - /** * Creates a new {@link PagedResourcesAssemblerArgumentResolver} using the given * {@link PageableHandlerMethodArgumentResolver}. diff --git a/src/test/java/org/springframework/data/mapping/InstantiationAwarePersistentPropertyAccessorUnitTests.java b/src/test/java/org/springframework/data/mapping/InstantiationAwarePersistentPropertyAccessorUnitTests.java index 0e74e5427..7314ee3d4 100644 --- a/src/test/java/org/springframework/data/mapping/InstantiationAwarePersistentPropertyAccessorUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/InstantiationAwarePersistentPropertyAccessorUnitTests.java @@ -41,9 +41,10 @@ class InstantiationAwarePersistentPropertyAccessorUnitTests { PersistentEntity entity = context.getRequiredPersistentEntity(Sample.class); - PersistentPropertyAccessor accessor = entity.getPropertyAccessor(new Sample("Dave", "Matthews", 42)); + Sample sample = new Sample("Dave", "Matthews", 42); - PersistentPropertyAccessor wrapper = new InstantiationAwarePropertyAccessor<>(accessor, + PersistentPropertyAccessor wrapper = new InstantiationAwarePropertyAccessor<>(sample, + entity::getPropertyAccessor, instantiators); wrapper.setProperty(entity.getRequiredPersistentProperty("firstname"), "Oliver August"); diff --git a/src/test/java/org/springframework/data/repository/cdi/CdiRepositoryBeanUnitTests.java b/src/test/java/org/springframework/data/repository/cdi/CdiRepositoryBeanUnitTests.java index 60ee545ab..4fee582cd 100755 --- a/src/test/java/org/springframework/data/repository/cdi/CdiRepositoryBeanUnitTests.java +++ b/src/test/java/org/springframework/data/repository/cdi/CdiRepositoryBeanUnitTests.java @@ -37,12 +37,16 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; + import org.springframework.aop.framework.ProxyFactory; import org.springframework.data.repository.Repository; import org.springframework.data.repository.config.CustomRepositoryImplementationDetector; import org.springframework.data.repository.config.ImplementationLookupConfiguration; import org.springframework.data.repository.core.NamedQueries; import org.springframework.data.repository.core.RepositoryInformation; +import org.springframework.data.repository.core.support.DummyRepositoryFactory; import org.springframework.data.repository.core.support.PropertiesBasedNamedQueries; import org.springframework.data.repository.core.support.QueryCreationListener; import org.springframework.data.repository.core.support.RepositoryFactorySupport; @@ -60,6 +64,7 @@ import org.springframework.data.repository.query.RepositoryQuery; * @author Kyrylo Merzlikin */ @ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.LENIENT) class CdiRepositoryBeanUnitTests { static final String PASSIVATION_ID = "javax.enterprise.inject.Default:org.springframework.data.repository.cdi.CdiRepositoryBeanUnitTests$SampleRepository"; @@ -148,8 +153,8 @@ class CdiRepositoryBeanUnitTests { @Override protected SampleRepository create(CreationalContext creationalContext, - Class repositoryType, Optional customImplementation) { - return null; + Class repositoryType) { + return create(() -> new DummyRepositoryFactory(new Object()), repositoryType); } }; @@ -158,9 +163,9 @@ class CdiRepositoryBeanUnitTests { ArgumentCaptor captor = ArgumentCaptor .forClass(ImplementationLookupConfiguration.class); - verify(detector).detectCustomImplementation(captor.capture()); + verify(detector, times(2)).detectCustomImplementation(captor.capture()); - ImplementationLookupConfiguration configuration = captor.getValue(); + ImplementationLookupConfiguration configuration = captor.getAllValues().get(0); assertThat(configuration.getImplementationBeanName()).isEqualTo("cdiRepositoryBeanUnitTests.SampleRepositoryImpl"); assertThat(configuration.getImplementationClassName()).isEqualTo("SampleRepositoryImpl"); @@ -194,8 +199,7 @@ class CdiRepositoryBeanUnitTests { } @Override - protected T create(CreationalContext creationalContext, Class repositoryType, - Optional customImplementation) { + protected T create(CreationalContext creationalContext, Class repositoryType) { return null; } } diff --git a/src/test/java/org/springframework/data/repository/support/PageableExecutionUtilsUnitTests.java b/src/test/java/org/springframework/data/repository/support/PageableExecutionUtilsUnitTests.java deleted file mode 100755 index 6606c181a..000000000 --- a/src/test/java/org/springframework/data/repository/support/PageableExecutionUtilsUnitTests.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2016-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.repository.support; - -import static org.assertj.core.api.Assertions.*; -import static org.mockito.Mockito.*; - -import java.util.Arrays; -import java.util.Collections; -import java.util.function.LongSupplier; - -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.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; - -/** - * Unit tests for {@link PageableExecutionUtils}. - * - * @author Mark Paluch - * @author Oliver Gierke - */ -@ExtendWith(MockitoExtension.class) -class PageableExecutionUtilsUnitTests { - - @Mock LongSupplier totalSupplierMock; - - @Test // DATAMCNS-884 - void firstPageRequestIsLessThanOneFullPageDoesNotRequireTotal() { - - Page page = PageableExecutionUtils.getPage(Arrays.asList(1, 2, 3), PageRequest.of(0, 10), - totalSupplierMock); - - assertThat(page).contains(1, 2, 3); - assertThat(page.getTotalElements()).isEqualTo(3L); - verifyNoInteractions(totalSupplierMock); - } - - @Test // DATAMCNS-884 - void noPageableRequestDoesNotRequireTotal() { - - Page page = PageableExecutionUtils.getPage(Arrays.asList(1, 2, 3), Pageable.unpaged(), totalSupplierMock); - - assertThat(page).contains(1, 2, 3); - assertThat(page.getTotalElements()).isEqualTo(3L); - - verifyNoInteractions(totalSupplierMock); - } - - @Test // DATAMCNS-884 - void subsequentPageRequestIsLessThanOneFullPageDoesNotRequireTotal() { - - Page page = PageableExecutionUtils.getPage(Arrays.asList(1, 2, 3), PageRequest.of(5, 10), - totalSupplierMock); - - assertThat(page).contains(1, 2, 3); - assertThat(page.getTotalElements()).isEqualTo(53L); - - verifyNoInteractions(totalSupplierMock); - } - - @Test // DATAMCNS-884 - void firstPageRequestHitsUpperBoundRequiresTotal() { - - doReturn(4L).when(totalSupplierMock).getAsLong(); - - Page page = PageableExecutionUtils.getPage(Arrays.asList(1, 2, 3), PageRequest.of(0, 3), - totalSupplierMock); - - assertThat(page).contains(1, 2, 3); - assertThat(page.getTotalElements()).isEqualTo(4L); - - verify(totalSupplierMock).getAsLong(); - } - - @Test // DATAMCNS-884 - void subsequentPageRequestHitsUpperBoundRequiresTotal() { - - doReturn(7L).when(totalSupplierMock).getAsLong(); - - Page page = PageableExecutionUtils.getPage(Arrays.asList(1, 2, 3), PageRequest.of(1, 3), - totalSupplierMock); - - assertThat(page).contains(1, 2, 3); - assertThat(page.getTotalElements()).isEqualTo(7L); - - verify(totalSupplierMock).getAsLong(); - } - - @Test // DATAMCNS-884 - void subsequentPageRequestWithoutResultRequiresRequireTotal() { - - doReturn(7L).when(totalSupplierMock).getAsLong(); - Page page = PageableExecutionUtils.getPage(Collections. emptyList(), PageRequest.of(5, 10), - totalSupplierMock); - - assertThat(page.getTotalElements()).isEqualTo(7L); - - verify(totalSupplierMock).getAsLong(); - } -} diff --git a/src/test/java/org/springframework/data/repository/util/QueryExecutionConvertersUnitTests.java b/src/test/java/org/springframework/data/repository/util/QueryExecutionConvertersUnitTests.java index 58dbb5a21..c65e9b2c7 100755 --- a/src/test/java/org/springframework/data/repository/util/QueryExecutionConvertersUnitTests.java +++ b/src/test/java/org/springframework/data/repository/util/QueryExecutionConvertersUnitTests.java @@ -47,6 +47,7 @@ import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.data.domain.Page; import org.springframework.data.domain.Slice; import org.springframework.data.util.ClassTypeInformation; +import org.springframework.data.util.NullableWrapper; import org.springframework.data.util.Streamable; import org.springframework.data.util.TypeInformation; import org.springframework.util.concurrent.ListenableFuture; diff --git a/src/test/java/org/springframework/data/util/KotlinReflectionUtilsUnitTests.java b/src/test/java/org/springframework/data/util/KotlinReflectionUtilsUnitTests.java index a4617e69a..3ca6b3926 100644 --- a/src/test/java/org/springframework/data/util/KotlinReflectionUtilsUnitTests.java +++ b/src/test/java/org/springframework/data/util/KotlinReflectionUtilsUnitTests.java @@ -25,6 +25,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.core.KotlinDetector; +import org.springframework.data.mapping.model.TypeCreatingSyntheticClassKt; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -58,6 +59,21 @@ public class KotlinReflectionUtilsUnitTests { assertThat(KotlinReflectionUtils.isSupportedKotlinClass(TypeCreatingSyntheticClass.class)).isFalse(); } + @Test // DATACMNS-1171 + public void discoversKotlinClass() { + + assertThat(KotlinDetector.isKotlinType(TypeCreatingSyntheticClass.class)).isTrue(); + assertThat(KotlinReflectionUtils.isSupportedKotlinClass(TypeCreatingSyntheticClass.class)).isTrue(); + } + + @Test // DATACMNS-1171 + public void discoversUnsupportedKotlinClass() { + + assertThat(KotlinDetector.isKotlinType(org.springframework.data.mapping.model.TypeCreatingSyntheticClassKt.class)) + .isTrue(); + assertThat(KotlinReflectionUtils.isSupportedKotlinClass(TypeCreatingSyntheticClassKt.class)).isFalse(); + } + void runTest(String testName) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException { diff --git a/src/test/java/org/springframework/data/util/ReflectionUtilsUnitTests.java b/src/test/java/org/springframework/data/util/ReflectionUtilsUnitTests.java index 8c81553f1..13dd3aedc 100755 --- a/src/test/java/org/springframework/data/util/ReflectionUtilsUnitTests.java +++ b/src/test/java/org/springframework/data/util/ReflectionUtilsUnitTests.java @@ -27,7 +27,6 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.MethodParameter; -import org.springframework.data.mapping.model.TypeCreatingSyntheticClassKt; import org.springframework.data.repository.sample.User; import org.springframework.data.util.ReflectionUtils.DescribedFieldFilter; import org.springframework.util.ReflectionUtils.FieldFilter; @@ -38,46 +37,46 @@ import org.springframework.util.ReflectionUtils.FieldFilter; * @author Oliver Gierke * @author Mark Paluch */ -public class ReflectionUtilsUnitTests { +class ReflectionUtilsUnitTests { - @SuppressWarnings("rawtypes") Constructor constructor; - Field reference; + @SuppressWarnings("rawtypes") private Constructor constructor; + private Field reference; @BeforeEach - public void setUp() throws Exception { + void setUp() throws Exception { this.reference = Sample.class.getField("field"); this.constructor = ConstructorDetection.class.getConstructor(int.class, String.class); } @Test - public void findsFieldByFilter() { + void findsFieldByFilter() { Field field = ReflectionUtils.findField(Sample.class, (FieldFilter) new FieldNameFieldFilter("field")); assertThat(field).isEqualTo(reference); } @Test - public void returnsNullIfNoFieldFound() { + void returnsNullIfNoFieldFound() { Field field = ReflectionUtils.findField(Sample.class, (FieldFilter) new FieldNameFieldFilter("foo")); assertThat(field).isNull(); } @Test - public void rejectsNonUniqueField() { + void rejectsNonUniqueField() { assertThatIllegalStateException().isThrownBy( () -> ReflectionUtils.findField(Sample.class, new ReflectionUtils.AnnotationFieldFilter(Autowired.class))); } @Test - public void findsUniqueField() { + void findsUniqueField() { Field field = ReflectionUtils.findField(Sample.class, new FieldNameFieldFilter("field"), false); assertThat(field).isEqualTo(reference); } @Test - public void findsFieldInSuperclass() { + void findsFieldInSuperclass() { class Subclass extends Sample { @@ -88,7 +87,7 @@ public class ReflectionUtilsUnitTests { } @Test - public void setsNonPublicField() { + void setsNonPublicField() { Sample sample = new Sample(); Field field = ReflectionUtils.findField(Sample.class, new FieldNameFieldFilter("first")); @@ -97,48 +96,48 @@ public class ReflectionUtilsUnitTests { } @Test // DATACMNS-542 - public void detectsConstructorForCompleteMatch() throws Exception { + void detectsConstructorForCompleteMatch() throws Exception { assertThat(ReflectionUtils.findConstructor(ConstructorDetection.class, 2, "test")).hasValue(constructor); } @Test // DATACMNS-542 - public void detectsConstructorForMatchWithNulls() throws Exception { + void detectsConstructorForMatchWithNulls() throws Exception { assertThat(ReflectionUtils.findConstructor(ConstructorDetection.class, 2, null)).hasValue(constructor); } @Test // DATACMNS-542 - public void rejectsConstructorIfNumberOfArgumentsDontMatch() throws Exception { + void rejectsConstructorIfNumberOfArgumentsDontMatch() throws Exception { assertThat(ReflectionUtils.findConstructor(ConstructorDetection.class, 2, "test", "test")).isNotPresent(); } @Test // DATACMNS-542 - public void rejectsConstructorForNullForPrimitiveArgument() throws Exception { + void rejectsConstructorForNullForPrimitiveArgument() throws Exception { assertThat(ReflectionUtils.findConstructor(ConstructorDetection.class, null, "test")).isNotPresent(); } @Test // DATACMNS-1154 - public void discoversNoReturnType() throws Exception { + void discoversNoReturnType() throws Exception { MethodParameter parameter = new MethodParameter(DummyInterface.class.getDeclaredMethod("noReturnValue"), -1); assertThat(ReflectionUtils.isNullable(parameter)).isTrue(); } @Test // DATACMNS-1154 - public void discoversNullableReturnType() throws Exception { + void discoversNullableReturnType() throws Exception { MethodParameter parameter = new MethodParameter(DummyInterface.class.getDeclaredMethod("nullableReturnValue"), -1); assertThat(ReflectionUtils.isNullable(parameter)).isTrue(); } @Test // DATACMNS-1154 - public void discoversNonNullableReturnType() throws Exception { + void discoversNonNullableReturnType() throws Exception { MethodParameter parameter = new MethodParameter(DummyInterface.class.getDeclaredMethod("mandatoryReturnValue"), -1); assertThat(ReflectionUtils.isNullable(parameter)).isFalse(); } @Test // DATACMNS-1154 - public void discoversNullableParameter() throws Exception { + void discoversNullableParameter() throws Exception { MethodParameter parameter = new MethodParameter( DummyInterface.class.getDeclaredMethod("nullableParameter", User.class), 0); @@ -146,28 +145,14 @@ public class ReflectionUtilsUnitTests { } @Test // DATACMNS-1154 - public void discoversNonNullablePrimitiveParameter() throws Exception { + void discoversNonNullablePrimitiveParameter() throws Exception { MethodParameter parameter = new MethodParameter(DummyInterface.class.getDeclaredMethod("primitive", int.class), 0); assertThat(ReflectionUtils.isNullable(parameter)).isFalse(); } - @Test // DATACMNS-1171 - public void discoversKotlinClass() { - - assertThat(ReflectionUtils.isKotlinClass(TypeCreatingSyntheticClass.class)).isTrue(); - assertThat(ReflectionUtils.isSupportedKotlinClass(TypeCreatingSyntheticClass.class)).isTrue(); - } - - @Test // DATACMNS-1171 - public void discoversUnsupportedKotlinClass() { - - assertThat(ReflectionUtils.isKotlinClass(TypeCreatingSyntheticClassKt.class)).isTrue(); - assertThat(ReflectionUtils.isSupportedKotlinClass(TypeCreatingSyntheticClassKt.class)).isFalse(); - } - @Test // DATACMNS-1779 - public void shouldReportIsVoid() { + void shouldReportIsVoid() { assertThat(ReflectionUtils.isVoid(Void.class)).isTrue(); assertThat(ReflectionUtils.isVoid(Void.TYPE)).isTrue(); @@ -186,7 +171,7 @@ public class ReflectionUtilsUnitTests { private final String name; - public FieldNameFieldFilter(String name) { + FieldNameFieldFilter(String name) { this.name = name; }