From 228d9db4d4885f5b650f9a5210b2b8f9395eebf9 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 27 Feb 2015 19:27:37 +0100 Subject: [PATCH] Polish StreamConverter(Tests) --- .../core/convert/support/StreamConverter.java | 4 ++-- .../convert/support/StreamConverterTests.java | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/StreamConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/StreamConverter.java index 0d51c2af18..425c11576c 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/StreamConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/StreamConverter.java @@ -29,7 +29,7 @@ import org.springframework.core.convert.converter.ConditionalGenericConverter; import org.springframework.lang.UsesJava8; /** - * Convert a {@link Stream} to an from a collection or array, converting the + * Converts a {@link Stream} to and from a collection or array, converting the * element type if necessary. * * @author Stephane Nicoll @@ -77,7 +77,7 @@ public class StreamConverter implements ConditionalGenericConverter { /** * Validate that the specified {@code sourceType} can be converted to a {@link Collection} of - * type type of the stream elements + * the type of the stream elements. * @param elementType the type of the stream elements * @param sourceType the type to convert from */ diff --git a/spring-core/src/test/java/org/springframework/core/convert/support/StreamConverterTests.java b/spring-core/src/test/java/org/springframework/core/convert/support/StreamConverterTests.java index bb1c205cd5..6b09204e84 100644 --- a/spring-core/src/test/java/org/springframework/core/convert/support/StreamConverterTests.java +++ b/spring-core/src/test/java/org/springframework/core/convert/support/StreamConverterTests.java @@ -34,20 +34,23 @@ import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.core.Is.is; import static org.junit.Assert.*; +/** + * Tests for {@link StreamConverter}. + * + * @author Stephane Nicoll + * @since 4.2 + */ public class StreamConverterTests { @Rule public final ExpectedException thrown = ExpectedException.none(); - private GenericConversionService conversionService; + private final GenericConversionService conversionService = new GenericConversionService(); - private StreamConverter streamConverter; + private final StreamConverter streamConverter = new StreamConverter(this.conversionService); @Before public void setup() { - this.conversionService = new GenericConversionService(); - this.streamConverter = new StreamConverter(this.conversionService); - this.conversionService.addConverter(new CollectionToCollectionConverter(this.conversionService)); this.conversionService.addConverter(new ArrayToCollectionConverter(this.conversionService)); this.conversionService.addConverter(new CollectionToArrayConverter(this.conversionService)); @@ -111,6 +114,7 @@ public class StreamConverterTests { } @Test + @SuppressWarnings("resource") public void convertFromListToStream() throws NoSuchFieldException { this.conversionService.addConverterFactory(new StringToNumberConverterFactory()); List stream = Arrays.asList("1", "2", "3"); @@ -124,6 +128,7 @@ public class StreamConverterTests { } @Test + @SuppressWarnings("resource") public void convertFromArrayToStream() throws NoSuchFieldException { Integer[] stream = new Integer[] {1, 0, 1}; this.conversionService.addConverter(new Converter() { @@ -142,6 +147,7 @@ public class StreamConverterTests { } @Test + @SuppressWarnings("resource") public void convertFromListToRawStream() throws NoSuchFieldException { List stream = Arrays.asList("1", "2", "3"); TypeDescriptor streamOfInteger = new TypeDescriptor(Types.class.getField("rawStream")); ; @@ -169,7 +175,7 @@ public class StreamConverterTests { new TypeDescriptor(Types.class.getField("arrayOfLongs"))); } - @SuppressWarnings("unused") + @SuppressWarnings({ "rawtypes" }) static class Types { public List listOfStrings;