mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 16:39:29 +00:00
Merge branch '7.0.x'
This commit is contained in:
+15
-13
@@ -162,31 +162,27 @@ class CollectionToCollectionConverterTests {
|
||||
|
||||
@Test
|
||||
void convertEmptyVector_shouldReturnEmptyArrayList() {
|
||||
Vector<String> vector = new Vector<>();
|
||||
vector.add("Element");
|
||||
testCollectionConversionToArrayList(vector);
|
||||
Object convertedValue = convertVectorToArrayList(new Vector<>());
|
||||
assertThat(convertedValue)
|
||||
.isInstanceOf(ArrayList.class)
|
||||
.asInstanceOf(LIST).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void convertNonEmptyVector_shouldReturnNonEmptyArrayList() {
|
||||
Vector<String> vector = new Vector<>();
|
||||
vector.add("Element");
|
||||
testCollectionConversionToArrayList(vector);
|
||||
Object convertedValue = convertVectorToArrayList(vector);
|
||||
assertThat(convertedValue)
|
||||
.isInstanceOf(ArrayList.class)
|
||||
.asInstanceOf(LIST).containsOnly("Element");
|
||||
}
|
||||
|
||||
@Test
|
||||
void collectionsEmptyList() throws Exception {
|
||||
CollectionToCollectionConverter converter = new CollectionToCollectionConverter(new GenericConversionService());
|
||||
TypeDescriptor type = new TypeDescriptor(getClass().getField("list"));
|
||||
converter.convert(list, type, TypeDescriptor.valueOf(Class.forName("java.util.Collections$EmptyList")));
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void testCollectionConversionToArrayList(Collection<String> source) {
|
||||
CollectionToCollectionConverter converter = new CollectionToCollectionConverter(new GenericConversionService());
|
||||
Object convertedValue = converter.convert(
|
||||
source, TypeDescriptor.forObject(source), TypeDescriptor.forObject(new ArrayList()));
|
||||
assertThat(convertedValue).asInstanceOf(LIST).hasSameSizeAs(source);
|
||||
assertThat(converter.convert(list, type, TypeDescriptor.valueOf(Class.forName("java.util.Collections$EmptyList")))).isSameAs(list);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -256,6 +252,12 @@ class CollectionToCollectionConverterTests {
|
||||
}
|
||||
|
||||
|
||||
private static Object convertVectorToArrayList(Vector<String> vector) {
|
||||
CollectionToCollectionConverter converter = new CollectionToCollectionConverter(new GenericConversionService());
|
||||
return converter.convert(vector, TypeDescriptor.forObject(vector), TypeDescriptor.valueOf(ArrayList.class));
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<Integer> scalarListTarget;
|
||||
|
||||
public List<Integer> emptyListTarget;
|
||||
|
||||
Reference in New Issue
Block a user