Migrate code to Java 17 style.
Use var instead of explicit local types where applicable. Use pattern variable instead instanceof and cast. Prefer loops and nullable types over Stream and Optional. Convert classes to records where applicable. See #2465
This commit is contained in:
committed by
Jens Schauder
parent
d4036ec0a9
commit
c735b58607
@@ -51,8 +51,8 @@ class MapAccessingMethodInterceptorUnitTests {
|
||||
when(invocation.proceed()).thenReturn(map.toString());
|
||||
when(invocation.getMethod()).thenReturn(Object.class.getMethod("toString"));
|
||||
|
||||
MapAccessingMethodInterceptor interceptor = new MapAccessingMethodInterceptor(map);
|
||||
Object result = interceptor.invoke(invocation);
|
||||
var interceptor = new MapAccessingMethodInterceptor(map);
|
||||
var result = interceptor.invoke(invocation);
|
||||
|
||||
assertThat(result).isEqualTo(map.toString());
|
||||
}
|
||||
@@ -65,7 +65,7 @@ class MapAccessingMethodInterceptorUnitTests {
|
||||
when(invocation.getMethod()).thenReturn(Sample.class.getMethod("setName", String.class));
|
||||
when(invocation.getArguments()).thenReturn(new Object[] { "Foo" });
|
||||
|
||||
Object result = new MapAccessingMethodInterceptor(map).invoke(invocation);
|
||||
var result = new MapAccessingMethodInterceptor(map).invoke(invocation);
|
||||
|
||||
assertThat(result).isNull();
|
||||
assertThat(map.get("name")).isEqualTo("Foo");
|
||||
@@ -79,7 +79,7 @@ class MapAccessingMethodInterceptorUnitTests {
|
||||
|
||||
when(invocation.getMethod()).thenReturn(Sample.class.getMethod("getName"));
|
||||
|
||||
Object result = new MapAccessingMethodInterceptor(map).invoke(invocation);
|
||||
var result = new MapAccessingMethodInterceptor(map).invoke(invocation);
|
||||
|
||||
assertThat(result).isEqualTo("Foo");
|
||||
}
|
||||
|
||||
@@ -117,12 +117,12 @@ class ProjectingMethodInterceptorUnitTests {
|
||||
|
||||
MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(new ProxyProjectionFactory(), interceptor,
|
||||
conversionService);
|
||||
Object result = methodInterceptor
|
||||
var result = methodInterceptor
|
||||
.invoke(mockInvocationOf("getHelperCollection", Collections.singleton(mock(Helper.class))));
|
||||
|
||||
assertThat(result).isInstanceOf(Set.class);
|
||||
|
||||
Set<Object> projections = (Set<Object>) result;
|
||||
var projections = (Set<Object>) result;
|
||||
assertThat(projections).hasSize(1).hasOnlyElementsOfType(HelperProjection.class);
|
||||
}
|
||||
|
||||
@@ -132,12 +132,12 @@ class ProjectingMethodInterceptorUnitTests {
|
||||
|
||||
MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(new ProxyProjectionFactory(), interceptor,
|
||||
conversionService);
|
||||
Object result = methodInterceptor
|
||||
var result = methodInterceptor
|
||||
.invoke(mockInvocationOf("getHelperList", Collections.singletonList(mock(Helper.class))));
|
||||
|
||||
assertThat(result).isInstanceOf(List.class);
|
||||
|
||||
List<Object> projections = (List<Object>) result;
|
||||
var projections = (List<Object>) result;
|
||||
|
||||
assertThat(projections).hasSize(1).hasOnlyElementsOfType(HelperProjection.class);
|
||||
}
|
||||
@@ -148,11 +148,11 @@ class ProjectingMethodInterceptorUnitTests {
|
||||
|
||||
MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(new ProxyProjectionFactory(), interceptor,
|
||||
conversionService);
|
||||
Object result = methodInterceptor.invoke(mockInvocationOf("getHelperArray", new Helper[] { mock(Helper.class) }));
|
||||
var result = methodInterceptor.invoke(mockInvocationOf("getHelperArray", new Helper[] { mock(Helper.class) }));
|
||||
|
||||
assertThat(result).isInstanceOf(Collection.class);
|
||||
|
||||
Collection<Object> projections = (Collection<Object>) result;
|
||||
var projections = (Collection<Object>) result;
|
||||
|
||||
assertThat(projections).hasSize(1).hasOnlyElementsOfType(HelperProjection.class);
|
||||
}
|
||||
@@ -164,12 +164,12 @@ class ProjectingMethodInterceptorUnitTests {
|
||||
MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(new ProxyProjectionFactory(), interceptor,
|
||||
conversionService);
|
||||
|
||||
Object result = methodInterceptor
|
||||
var result = methodInterceptor
|
||||
.invoke(mockInvocationOf("getHelperMap", Collections.singletonMap("foo", mock(Helper.class))));
|
||||
|
||||
assertThat(result).isInstanceOf(Map.class);
|
||||
|
||||
Map<String, Object> projections = (Map<String, Object>) result;
|
||||
var projections = (Map<String, Object>) result;
|
||||
|
||||
assertThat(projections).hasSize(1).matches(map -> map.get("foo") instanceof HelperProjection);
|
||||
}
|
||||
@@ -180,12 +180,12 @@ class ProjectingMethodInterceptorUnitTests {
|
||||
MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(new ProxyProjectionFactory(), interceptor,
|
||||
conversionService);
|
||||
|
||||
Helper reference = mock(Helper.class);
|
||||
Object result = methodInterceptor.invoke(mockInvocationOf("getHelperCollection", reference));
|
||||
var reference = mock(Helper.class);
|
||||
var result = methodInterceptor.invoke(mockInvocationOf("getHelperCollection", reference));
|
||||
|
||||
assertThat(result).isInstanceOf(Collection.class);
|
||||
|
||||
Collection<?> collection = (Collection<?>) result;
|
||||
var collection = (Collection<?>) result;
|
||||
|
||||
assertThat(collection).hasSize(1).hasOnlyElementsOfType(HelperProjection.class);
|
||||
}
|
||||
@@ -196,12 +196,12 @@ class ProjectingMethodInterceptorUnitTests {
|
||||
MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(new ProxyProjectionFactory(), interceptor,
|
||||
conversionService);
|
||||
|
||||
Object result = methodInterceptor
|
||||
var result = methodInterceptor
|
||||
.invoke(mockInvocationOf("getHelperEnumSet", Collections.singletonList(HelperEnum.Helpful)));
|
||||
|
||||
assertThat(result).isInstanceOf(EnumSet.class);
|
||||
|
||||
Collection<HelperEnum> collection = (Collection<HelperEnum>) result;
|
||||
var collection = (Collection<HelperEnum>) result;
|
||||
assertThat(collection).containsOnly(HelperEnum.Helpful);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,10 +21,8 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.jayway.jsonpath.Configuration.ConfigurationBuilder;
|
||||
import com.jayway.jsonpath.DocumentContext;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import com.jayway.jsonpath.Option;
|
||||
import com.jayway.jsonpath.ParseContext;
|
||||
|
||||
/**
|
||||
* Integration tests for projections.
|
||||
@@ -36,11 +34,11 @@ class ProjectionIntegrationTests {
|
||||
@Test // DATACMNS-909
|
||||
void jacksonSerializationDoesNotExposeDecoratedClass() throws Exception {
|
||||
|
||||
ProxyProjectionFactory factory = new ProxyProjectionFactory();
|
||||
SampleProjection projection = factory.createProjection(SampleProjection.class);
|
||||
var factory = new ProxyProjectionFactory();
|
||||
var projection = factory.createProjection(SampleProjection.class);
|
||||
|
||||
ParseContext context = JsonPath.using(new ConfigurationBuilder().options(Option.SUPPRESS_EXCEPTIONS).build());
|
||||
DocumentContext json = context.parse(new ObjectMapper().writeValueAsString(projection));
|
||||
var context = JsonPath.using(new ConfigurationBuilder().options(Option.SUPPRESS_EXCEPTIONS).build());
|
||||
var json = context.parse(new ObjectMapper().writeValueAsString(projection));
|
||||
|
||||
assertThat(json.read("$.decoratedClass", String.class)).isNull();
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class PropertyAccessingMethodInterceptorUnitTests {
|
||||
@Test // DATAREST-221
|
||||
void triggersPropertyAccessOnTarget() throws Throwable {
|
||||
|
||||
Source source = new Source();
|
||||
var source = new Source();
|
||||
source.firstname = "Dave";
|
||||
|
||||
when(invocation.getMethod()).thenReturn(Projection.class.getMethod("getFirstname"));
|
||||
@@ -79,7 +79,7 @@ class PropertyAccessingMethodInterceptorUnitTests {
|
||||
@Test // DATACMNS-820
|
||||
void triggersWritePropertyAccessOnTarget() throws Throwable {
|
||||
|
||||
Source source = new Source();
|
||||
var source = new Source();
|
||||
source.firstname = "Dave";
|
||||
|
||||
when(invocation.getMethod()).thenReturn(Projection.class.getMethod("setFirstname", String.class));
|
||||
@@ -93,7 +93,7 @@ class PropertyAccessingMethodInterceptorUnitTests {
|
||||
@Test // DATACMNS-820
|
||||
void throwsAppropriateExceptionIfTheInvocationHasNoArguments() throws Throwable {
|
||||
|
||||
Source source = new Source();
|
||||
var source = new Source();
|
||||
|
||||
when(invocation.getMethod()).thenReturn(Projection.class.getMethod("setFirstname", String.class));
|
||||
when(invocation.getArguments()).thenReturn(new Object[0]);
|
||||
|
||||
@@ -17,7 +17,6 @@ package org.springframework.data.projection;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Calendar;
|
||||
@@ -25,12 +24,11 @@ import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
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.test.util.ReflectionTestUtils;
|
||||
@@ -70,7 +68,7 @@ class ProxyProjectionFactoryUnitTests {
|
||||
@Test // DATAREST-221, DATACMNS-630
|
||||
void createsProjectingProxy() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
var customer = new Customer();
|
||||
customer.firstname = "Dave";
|
||||
customer.lastname = "Matthews";
|
||||
|
||||
@@ -78,7 +76,7 @@ class ProxyProjectionFactoryUnitTests {
|
||||
customer.address.city = "New York";
|
||||
customer.address.zipCode = "ZIP";
|
||||
|
||||
CustomerExcerpt excerpt = factory.createProjection(CustomerExcerpt.class, customer);
|
||||
var excerpt = factory.createProjection(CustomerExcerpt.class, customer);
|
||||
|
||||
assertThat(excerpt.getFirstname()).isEqualTo("Dave");
|
||||
assertThat(excerpt.getAddress().getZipCode()).isEqualTo("ZIP");
|
||||
@@ -87,7 +85,7 @@ class ProxyProjectionFactoryUnitTests {
|
||||
@Test // DATAREST-221, DATACMNS-630
|
||||
void proxyExposesTargetClassAware() {
|
||||
|
||||
CustomerExcerpt proxy = factory.createProjection(CustomerExcerpt.class);
|
||||
var proxy = factory.createProjection(CustomerExcerpt.class);
|
||||
|
||||
assertThat(proxy).isInstanceOf(TargetClassAware.class);
|
||||
assertThat(((TargetClassAware) proxy).getTargetClass()).isEqualTo(HashMap.class);
|
||||
@@ -101,7 +99,7 @@ class ProxyProjectionFactoryUnitTests {
|
||||
@Test // DATACMNS-630
|
||||
void createsMapBasedProxyFromSource() {
|
||||
|
||||
HashMap<String, Object> addressSource = new HashMap<>();
|
||||
var addressSource = new HashMap<String, Object>();
|
||||
addressSource.put("zipCode", "ZIP");
|
||||
addressSource.put("city", "NewYork");
|
||||
|
||||
@@ -110,11 +108,11 @@ class ProxyProjectionFactoryUnitTests {
|
||||
source.put("lastname", "Matthews");
|
||||
source.put("address", addressSource);
|
||||
|
||||
CustomerExcerpt projection = factory.createProjection(CustomerExcerpt.class, source);
|
||||
var projection = factory.createProjection(CustomerExcerpt.class, source);
|
||||
|
||||
assertThat(projection.getFirstname()).isEqualTo("Dave");
|
||||
|
||||
AddressExcerpt address = projection.getAddress();
|
||||
var address = projection.getAddress();
|
||||
assertThat(address).isNotNull();
|
||||
assertThat(address.getZipCode()).isEqualTo("ZIP");
|
||||
}
|
||||
@@ -122,7 +120,7 @@ class ProxyProjectionFactoryUnitTests {
|
||||
@Test // DATACMNS-630
|
||||
void createsEmptyMapBasedProxy() {
|
||||
|
||||
CustomerProxy proxy = factory.createProjection(CustomerProxy.class);
|
||||
var proxy = factory.createProjection(CustomerProxy.class);
|
||||
|
||||
assertThat(proxy).isNotNull();
|
||||
|
||||
@@ -133,8 +131,8 @@ class ProxyProjectionFactoryUnitTests {
|
||||
@Test // DATACMNS-630
|
||||
void returnsAllPropertiesAsInputProperties() {
|
||||
|
||||
ProjectionInformation projectionInformation = factory.getProjectionInformation(CustomerExcerpt.class);
|
||||
List<PropertyDescriptor> result = projectionInformation.getInputProperties();
|
||||
var projectionInformation = factory.getProjectionInformation(CustomerExcerpt.class);
|
||||
var result = projectionInformation.getInputProperties();
|
||||
|
||||
assertThat(result).hasSize(6);
|
||||
}
|
||||
@@ -142,10 +140,10 @@ class ProxyProjectionFactoryUnitTests {
|
||||
@Test // DATACMNS-655
|
||||
void invokesDefaultMethodOnProxy() {
|
||||
|
||||
CustomerExcerpt excerpt = factory.createProjection(CustomerExcerpt.class);
|
||||
var excerpt = factory.createProjection(CustomerExcerpt.class);
|
||||
|
||||
Advised advised = (Advised) ReflectionTestUtils.getField(Proxy.getInvocationHandler(excerpt), "advised");
|
||||
Advisor[] advisors = advised.getAdvisors();
|
||||
var advised = (Advised) ReflectionTestUtils.getField(Proxy.getInvocationHandler(excerpt), "advised");
|
||||
var advisors = advised.getAdvisors();
|
||||
|
||||
assertThat(advisors.length).isGreaterThan(0);
|
||||
assertThat(advisors[0].getAdvice()).isInstanceOf(DefaultMethodInvokingMethodInterceptor.class);
|
||||
@@ -154,7 +152,7 @@ class ProxyProjectionFactoryUnitTests {
|
||||
@Test // DATACMNS-648
|
||||
void exposesProxyTarget() {
|
||||
|
||||
CustomerExcerpt excerpt = factory.createProjection(CustomerExcerpt.class);
|
||||
var excerpt = factory.createProjection(CustomerExcerpt.class);
|
||||
|
||||
assertThat(excerpt).isInstanceOf(TargetAware.class);
|
||||
assertThat(((TargetAware) excerpt).getTarget()).isInstanceOf(Map.class);
|
||||
@@ -163,10 +161,10 @@ class ProxyProjectionFactoryUnitTests {
|
||||
@Test // DATACMNS-722
|
||||
void doesNotProjectPrimitiveArray() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
var customer = new Customer();
|
||||
customer.picture = "binarydata".getBytes();
|
||||
|
||||
CustomerExcerpt excerpt = factory.createProjection(CustomerExcerpt.class, customer);
|
||||
var excerpt = factory.createProjection(CustomerExcerpt.class, customer);
|
||||
|
||||
assertThat(excerpt.getPicture()).isEqualTo(customer.picture);
|
||||
}
|
||||
@@ -174,14 +172,14 @@ class ProxyProjectionFactoryUnitTests {
|
||||
@Test // DATACMNS-722
|
||||
void projectsNonPrimitiveArray() {
|
||||
|
||||
Address address = new Address();
|
||||
var address = new Address();
|
||||
address.city = "New York";
|
||||
address.zipCode = "ZIP";
|
||||
|
||||
Customer customer = new Customer();
|
||||
var customer = new Customer();
|
||||
customer.shippingAddresses = new Address[] { address };
|
||||
|
||||
CustomerExcerpt excerpt = factory.createProjection(CustomerExcerpt.class, customer);
|
||||
var excerpt = factory.createProjection(CustomerExcerpt.class, customer);
|
||||
|
||||
assertThat(excerpt.getShippingAddresses()).hasSize(1);
|
||||
}
|
||||
@@ -189,10 +187,10 @@ class ProxyProjectionFactoryUnitTests {
|
||||
@Test // DATACMNS-782
|
||||
void convertsPrimitiveValues() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
var customer = new Customer();
|
||||
customer.id = 1L;
|
||||
|
||||
CustomerExcerpt excerpt = factory.createProjection(CustomerExcerpt.class, customer);
|
||||
var excerpt = factory.createProjection(CustomerExcerpt.class, customer);
|
||||
|
||||
assertThat(excerpt.getId()).isEqualTo(customer.id.toString());
|
||||
}
|
||||
@@ -200,7 +198,7 @@ class ProxyProjectionFactoryUnitTests {
|
||||
@Test // DATACMNS-89
|
||||
void exposesProjectionInformationCorrectly() {
|
||||
|
||||
ProjectionInformation information = factory.getProjectionInformation(CustomerExcerpt.class);
|
||||
var information = factory.getProjectionInformation(CustomerExcerpt.class);
|
||||
|
||||
assertThat(information.getType()).isEqualTo(CustomerExcerpt.class);
|
||||
assertThat(information.isClosed()).isTrue();
|
||||
@@ -209,10 +207,10 @@ class ProxyProjectionFactoryUnitTests {
|
||||
@Test // DATACMNS-829
|
||||
void projectsMapOfStringToObjectCorrectly() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
var customer = new Customer();
|
||||
customer.data = Collections.singletonMap("key", null);
|
||||
|
||||
Map<String, Object> data = factory.createProjection(CustomerExcerpt.class, customer).getData();
|
||||
var data = factory.createProjection(CustomerExcerpt.class, customer).getData();
|
||||
|
||||
assertThat(data).isNotNull();
|
||||
assertThat(data.containsKey("key")).isTrue();
|
||||
@@ -222,7 +220,7 @@ class ProxyProjectionFactoryUnitTests {
|
||||
@Test // DATACMNS-1121
|
||||
void doesNotCreateWrappingProxyIfTargetImplementsProjectionInterface() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
var customer = new Customer();
|
||||
|
||||
assertThat(factory.createProjection(Contact.class, customer)).isSameAs(customer);
|
||||
}
|
||||
@@ -230,10 +228,10 @@ class ProxyProjectionFactoryUnitTests {
|
||||
@Test // DATACMNS-1762
|
||||
void supportsOptionalAsReturnTypeIfEmpty() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
var customer = new Customer();
|
||||
customer.picture = null;
|
||||
|
||||
CustomerWithOptional excerpt = factory.createProjection(CustomerWithOptional.class, customer);
|
||||
var excerpt = factory.createProjection(CustomerWithOptional.class, customer);
|
||||
|
||||
assertThat(excerpt.getPicture()).isEmpty();
|
||||
}
|
||||
@@ -241,10 +239,10 @@ class ProxyProjectionFactoryUnitTests {
|
||||
@Test // DATACMNS-1762
|
||||
void supportsOptionalAsReturnTypeIfPresent() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
var customer = new Customer();
|
||||
customer.picture = new byte[] { 1, 2, 3 };
|
||||
|
||||
CustomerWithOptional excerpt = factory.createProjection(CustomerWithOptional.class, customer);
|
||||
var excerpt = factory.createProjection(CustomerWithOptional.class, customer);
|
||||
|
||||
assertThat(excerpt.getPicture()).hasValueSatisfying(bytes -> {
|
||||
assertThat(bytes).isEqualTo(new byte[] { 1, 2, 3 });
|
||||
@@ -254,10 +252,10 @@ class ProxyProjectionFactoryUnitTests {
|
||||
@Test // DATACMNS-1762
|
||||
void supportsOptionalBackedByOptional() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
var customer = new Customer();
|
||||
customer.optional = Optional.of("foo");
|
||||
|
||||
CustomerWithOptional excerpt = factory.createProjection(CustomerWithOptional.class, customer);
|
||||
var excerpt = factory.createProjection(CustomerWithOptional.class, customer);
|
||||
|
||||
assertThat(excerpt.getOptional()).hasValue("foo");
|
||||
}
|
||||
@@ -265,7 +263,7 @@ class ProxyProjectionFactoryUnitTests {
|
||||
@Test // DATACMNS-1762
|
||||
void supportsOptionalWithProjectionAsReturnTypeIfPresent() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
var customer = new Customer();
|
||||
customer.firstname = "Dave";
|
||||
customer.lastname = "Matthews";
|
||||
|
||||
@@ -273,7 +271,7 @@ class ProxyProjectionFactoryUnitTests {
|
||||
customer.address.city = "New York";
|
||||
customer.address.zipCode = "ZIP";
|
||||
|
||||
CustomerWithOptionalHavingProjection excerpt = factory.createProjection(CustomerWithOptionalHavingProjection.class,
|
||||
var excerpt = factory.createProjection(CustomerWithOptionalHavingProjection.class,
|
||||
customer);
|
||||
|
||||
assertThat(excerpt.getFirstname()).isEqualTo("Dave");
|
||||
@@ -285,7 +283,7 @@ class ProxyProjectionFactoryUnitTests {
|
||||
@Test // DATACMNS-1836
|
||||
void supportsDateToLocalDateTimeConversion() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
var customer = new Customer();
|
||||
customer.firstname = "Dave";
|
||||
customer.birthdate = new GregorianCalendar(1967, Calendar.JANUARY, 9).getTime();
|
||||
|
||||
@@ -293,7 +291,7 @@ class ProxyProjectionFactoryUnitTests {
|
||||
customer.address.city = "New York";
|
||||
customer.address.zipCode = "ZIP";
|
||||
|
||||
CustomerWithLocalDateTime excerpt = factory.createProjection(CustomerWithLocalDateTime.class, customer);
|
||||
var excerpt = factory.createProjection(CustomerWithLocalDateTime.class, customer);
|
||||
|
||||
assertThat(excerpt.getFirstname()).isEqualTo("Dave");
|
||||
assertThat(excerpt.getBirthdate()).isEqualTo(LocalDateTime.of(1967, 1, 9, 0, 0));
|
||||
@@ -302,7 +300,7 @@ class ProxyProjectionFactoryUnitTests {
|
||||
@Test // DATACMNS-1836
|
||||
void supportsNullableWrapperDateToLocalDateTimeConversion() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
var customer = new Customer();
|
||||
customer.firstname = "Dave";
|
||||
customer.birthdate = new GregorianCalendar(1967, Calendar.JANUARY, 9).getTime();
|
||||
|
||||
@@ -310,7 +308,7 @@ class ProxyProjectionFactoryUnitTests {
|
||||
customer.address.city = "New York";
|
||||
customer.address.zipCode = "ZIP";
|
||||
|
||||
CustomerWithOptional excerpt = factory.createProjection(CustomerWithOptional.class, customer);
|
||||
var excerpt = factory.createProjection(CustomerWithOptional.class, customer);
|
||||
|
||||
assertThat(excerpt.getFirstname()).isEqualTo("Dave");
|
||||
assertThat(excerpt.getBirthdate()).contains(LocalDateTime.of(1967, 1, 9, 0, 0));
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.data.projection;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -45,18 +44,18 @@ class SpelAwareProxyProjectionFactoryUnitTests {
|
||||
@Test // DATAREST-221, DATACMNS-630
|
||||
void exposesSpelInvokingMethod() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
var customer = new Customer();
|
||||
customer.firstname = "Dave";
|
||||
customer.lastname = "Matthews";
|
||||
|
||||
CustomerExcerpt excerpt = factory.createProjection(CustomerExcerpt.class, customer);
|
||||
var excerpt = factory.createProjection(CustomerExcerpt.class, customer);
|
||||
assertThat(excerpt.getFullName()).isEqualTo("Dave Matthews");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-630
|
||||
void excludesAtValueAnnotatedMethodsForInputProperties() {
|
||||
|
||||
List<PropertyDescriptor> properties = factory //
|
||||
var properties = factory //
|
||||
.getProjectionInformation(CustomerExcerpt.class) //
|
||||
.getInputProperties();
|
||||
|
||||
@@ -68,7 +67,7 @@ class SpelAwareProxyProjectionFactoryUnitTests {
|
||||
@Test // DATACMNS-89
|
||||
void considersProjectionUsingAtValueNotClosed() {
|
||||
|
||||
ProjectionInformation information = factory.getProjectionInformation(CustomerExcerpt.class);
|
||||
var information = factory.getProjectionInformation(CustomerExcerpt.class);
|
||||
|
||||
assertThat(information.isClosed()).isFalse();
|
||||
}
|
||||
@@ -76,10 +75,10 @@ class SpelAwareProxyProjectionFactoryUnitTests {
|
||||
@Test // DATACMNS-820
|
||||
void setsValueUsingProjection() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
var customer = new Customer();
|
||||
customer.firstname = "Dave";
|
||||
|
||||
CustomerExcerpt excerpt = factory.createProjection(CustomerExcerpt.class, customer);
|
||||
var excerpt = factory.createProjection(CustomerExcerpt.class, customer);
|
||||
excerpt.setFirstname("Carl");
|
||||
|
||||
assertThat(customer.firstname).isEqualTo("Carl");
|
||||
@@ -88,10 +87,10 @@ class SpelAwareProxyProjectionFactoryUnitTests {
|
||||
@Test // DATACMNS-820
|
||||
void settingNotWriteablePropertyFails() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
var customer = new Customer();
|
||||
customer.firstname = "Dave";
|
||||
|
||||
ProjectionWithNotWriteableProperty projection = factory.createProjection(ProjectionWithNotWriteableProperty.class,
|
||||
var projection = factory.createProjection(ProjectionWithNotWriteableProperty.class,
|
||||
customer);
|
||||
|
||||
assertThatExceptionOfType(NotWritablePropertyException.class).isThrownBy(() -> projection.setFirstName("Carl"));
|
||||
|
||||
@@ -62,10 +62,10 @@ class SpelEvaluatingMethodInterceptorUnitTests {
|
||||
|
||||
when(invocation.getMethod()).thenReturn(Projection.class.getMethod("invokeBean"));
|
||||
|
||||
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
|
||||
var factory = new DefaultListableBeanFactory();
|
||||
factory.registerSingleton("someBean", new SomeBean());
|
||||
|
||||
SpelEvaluatingMethodInterceptor interceptor = new SpelEvaluatingMethodInterceptor(delegate, new Target(), factory,
|
||||
var interceptor = new SpelEvaluatingMethodInterceptor(delegate, new Target(), factory,
|
||||
parser, Projection.class);
|
||||
|
||||
assertThat(interceptor.invoke(invocation)).isEqualTo("value");
|
||||
@@ -76,7 +76,7 @@ class SpelEvaluatingMethodInterceptorUnitTests {
|
||||
|
||||
when(invocation.getMethod()).thenReturn(Projection.class.getMethod("getName"));
|
||||
|
||||
SpelEvaluatingMethodInterceptor interceptor = new SpelEvaluatingMethodInterceptor(delegate, new Target(),
|
||||
var interceptor = new SpelEvaluatingMethodInterceptor(delegate, new Target(),
|
||||
new DefaultListableBeanFactory(), parser, Projection.class);
|
||||
|
||||
interceptor.invoke(invocation);
|
||||
@@ -98,7 +98,7 @@ class SpelEvaluatingMethodInterceptorUnitTests {
|
||||
|
||||
when(invocation.getMethod()).thenReturn(Projection.class.getMethod("propertyFromTarget"));
|
||||
|
||||
SpelEvaluatingMethodInterceptor interceptor = new SpelEvaluatingMethodInterceptor(delegate, map,
|
||||
var interceptor = new SpelEvaluatingMethodInterceptor(delegate, map,
|
||||
new DefaultListableBeanFactory(), parser, Projection.class);
|
||||
|
||||
assertThat(interceptor.invoke(invocation)).isEqualTo("Dave");
|
||||
@@ -107,7 +107,7 @@ class SpelEvaluatingMethodInterceptorUnitTests {
|
||||
@Test // DATACMNS-1150
|
||||
void forwardsParameterIntoSpElExpressionEvaluation() throws Throwable {
|
||||
|
||||
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
|
||||
var factory = new DefaultListableBeanFactory();
|
||||
factory.registerSingleton("someBean", new SomeBean());
|
||||
|
||||
when(invocation.getMethod()).thenReturn(Projection.class.getMethod("invokeBeanWithParameter", Integer.class));
|
||||
|
||||
Reference in New Issue
Block a user