diff --git a/spring-core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionConverterTests.java b/spring-core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionConverterTests.java index 65ffe4784f5..125631b7234 100644 --- a/spring-core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionConverterTests.java +++ b/spring-core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionConverterTests.java @@ -162,31 +162,27 @@ class CollectionToCollectionConverterTests { @Test void convertEmptyVector_shouldReturnEmptyArrayList() { - Vector 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 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 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 vector) { + CollectionToCollectionConverter converter = new CollectionToCollectionConverter(new GenericConversionService()); + return converter.convert(vector, TypeDescriptor.forObject(vector), TypeDescriptor.valueOf(ArrayList.class)); + } + + public ArrayList scalarListTarget; public List emptyListTarget;