Complete Vavr collection detection on TypeInformation and CustomConversions.
Moved Vavr collection converters into a type in the utility package. Register the converters via CustomConversions.registerConvertersIn(…) to make sure that all the Spring Data object mapping converters automatically benefit from a ConversionService that is capable of translating between Java-native collections and Vavr ones. Issue #2511.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2021 the original author or authors.
|
||||
* Copyright 2011-2022 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.
|
||||
@@ -22,6 +22,7 @@ import static org.mockito.Mockito.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
@@ -29,7 +30,6 @@ import java.util.function.Predicate;
|
||||
import org.jmolecules.ddd.types.Association;
|
||||
import org.jmolecules.ddd.types.Identifier;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.converter.ConverterFactory;
|
||||
@@ -261,6 +261,18 @@ class CustomConversionsUnitTests {
|
||||
assertThat(conversions.hasCustomReadTarget(String.class, Identifier.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test // GH-2511
|
||||
void registersVavrConverters() {
|
||||
|
||||
ConfigurableConversionService conversionService = new DefaultConversionService();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
private static Class<?> createProxyTypeFor(Class<?> type) {
|
||||
|
||||
var factory = new ProxyFactory();
|
||||
|
||||
@@ -179,34 +179,34 @@ public class TypeDiscovererUnitTests {
|
||||
assertThat(type.isSubTypeOf(String.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test // #2511
|
||||
void considerVavrMapToBeAMap() {
|
||||
|
||||
TypeInformation<io.vavr.collection.Map> type = from(io.vavr.collection.Map.class);
|
||||
var type = from(io.vavr.collection.Map.class);
|
||||
|
||||
assertThat(type.isMap()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test // #2511
|
||||
void considerVavrSetToBeCollectionLike() {
|
||||
|
||||
TypeInformation<io.vavr.collection.Set> type = from(io.vavr.collection.Set.class);
|
||||
var type = from(io.vavr.collection.Set.class);
|
||||
|
||||
assertThat(type.isCollectionLike()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test // #2511
|
||||
void considerVavrSeqToBeCollectionLike() {
|
||||
|
||||
TypeInformation<io.vavr.collection.Seq> type = from(io.vavr.collection.Seq.class);
|
||||
var type = from(io.vavr.collection.Seq.class);
|
||||
|
||||
assertThat(type.isCollectionLike()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test // #2511
|
||||
void considerVavrListToBeCollectionLike() {
|
||||
|
||||
TypeInformation<io.vavr.collection.List> type = from(io.vavr.collection.List.class);
|
||||
var type = from(io.vavr.collection.List.class);
|
||||
|
||||
assertThat(type.isCollectionLike()).isTrue();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user