Polishing.

Rename generics from C extends PersistentProperty to P extends PersistentProperty.
Refine conversion setup. Make PropertyValueConversions.getValueConverter(…) to return non-null. Return PropertyValueConversions from CustomConversions.

Resolves #2577
Closes #2592
This commit is contained in:
Mark Paluch
2022-04-05 11:21:46 +02:00
committed by John Blum
parent cb5201f9d2
commit cad739c337
6 changed files with 42 additions and 68 deletions

View File

@@ -42,7 +42,6 @@ import org.springframework.data.convert.CustomConversions.ConverterConfiguration
import org.springframework.data.convert.CustomConversions.StoreConversions;
import org.springframework.data.convert.Jsr310Converters.LocalDateTimeToDateConverter;
import org.springframework.data.geo.Point;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.model.SimpleTypeHolder;
/**
@@ -267,30 +266,17 @@ class CustomConversionsUnitTests {
ConfigurableConversionService conversionService = new DefaultConversionService();
new CustomConversions(StoreConversions.NONE, Collections.emptyList())
.registerConvertersIn(conversionService);
new CustomConversions(StoreConversions.NONE, Collections.emptyList()).registerConvertersIn(conversionService);
assertThat(conversionService.canConvert(io.vavr.collection.List.class, List.class)).isTrue();
assertThat(conversionService.canConvert(List.class, io.vavr.collection.List.class)).isTrue();
}
@Test // GH-1484
void allowsToRegisterPropertyConversions() {
PropertyValueConversions propertyValueConversions = mock(PropertyValueConversions.class);
when(propertyValueConversions.getValueConverter(any())).thenReturn(mock(PropertyValueConverter.class));
CustomConversions conversions = new CustomConversions(new ConverterConfiguration(StoreConversions.NONE,
Collections.emptyList(), (it) -> true, propertyValueConversions));
assertThat(conversions.getPropertyValueConverter(mock(PersistentProperty.class))).isNotNull();
}
@Test // GH-1484
void doesNotFailIfPropertiesConversionIsNull() {
CustomConversions conversions = new CustomConversions(new ConverterConfiguration(StoreConversions.NONE,
Collections.emptyList(), (it) -> true, null));
assertThat(conversions.getPropertyValueConverter(mock(PersistentProperty.class))).isNull();
new CustomConversions(
new ConverterConfiguration(StoreConversions.NONE, Collections.emptyList(), (it) -> true, null));
}
private static Class<?> createProxyTypeFor(Class<?> type) {