提交 228d9db4 编写于 作者: S Sam Brannen

Polish StreamConverter(Tests)

上级 fcd60b26
...@@ -29,7 +29,7 @@ import org.springframework.core.convert.converter.ConditionalGenericConverter; ...@@ -29,7 +29,7 @@ import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.lang.UsesJava8; 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. * element type if necessary.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
...@@ -77,7 +77,7 @@ public class StreamConverter implements ConditionalGenericConverter { ...@@ -77,7 +77,7 @@ public class StreamConverter implements ConditionalGenericConverter {
/** /**
* Validate that the specified {@code sourceType} can be converted to a {@link Collection} of * 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 elementType the type of the stream elements
* @param sourceType the type to convert from * @param sourceType the type to convert from
*/ */
......
...@@ -34,20 +34,23 @@ import static org.hamcrest.CoreMatchers.*; ...@@ -34,20 +34,23 @@ import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.core.Is.is; import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*; import static org.junit.Assert.*;
/**
* Tests for {@link StreamConverter}.
*
* @author Stephane Nicoll
* @since 4.2
*/
public class StreamConverterTests { public class StreamConverterTests {
@Rule @Rule
public final ExpectedException thrown = ExpectedException.none(); 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 @Before
public void setup() { public void setup() {
this.conversionService = new GenericConversionService();
this.streamConverter = new StreamConverter(this.conversionService);
this.conversionService.addConverter(new CollectionToCollectionConverter(this.conversionService)); this.conversionService.addConverter(new CollectionToCollectionConverter(this.conversionService));
this.conversionService.addConverter(new ArrayToCollectionConverter(this.conversionService)); this.conversionService.addConverter(new ArrayToCollectionConverter(this.conversionService));
this.conversionService.addConverter(new CollectionToArrayConverter(this.conversionService)); this.conversionService.addConverter(new CollectionToArrayConverter(this.conversionService));
...@@ -111,6 +114,7 @@ public class StreamConverterTests { ...@@ -111,6 +114,7 @@ public class StreamConverterTests {
} }
@Test @Test
@SuppressWarnings("resource")
public void convertFromListToStream() throws NoSuchFieldException { public void convertFromListToStream() throws NoSuchFieldException {
this.conversionService.addConverterFactory(new StringToNumberConverterFactory()); this.conversionService.addConverterFactory(new StringToNumberConverterFactory());
List<String> stream = Arrays.asList("1", "2", "3"); List<String> stream = Arrays.asList("1", "2", "3");
...@@ -124,6 +128,7 @@ public class StreamConverterTests { ...@@ -124,6 +128,7 @@ public class StreamConverterTests {
} }
@Test @Test
@SuppressWarnings("resource")
public void convertFromArrayToStream() throws NoSuchFieldException { public void convertFromArrayToStream() throws NoSuchFieldException {
Integer[] stream = new Integer[] {1, 0, 1}; Integer[] stream = new Integer[] {1, 0, 1};
this.conversionService.addConverter(new Converter<Integer, Boolean>() { this.conversionService.addConverter(new Converter<Integer, Boolean>() {
...@@ -142,6 +147,7 @@ public class StreamConverterTests { ...@@ -142,6 +147,7 @@ public class StreamConverterTests {
} }
@Test @Test
@SuppressWarnings("resource")
public void convertFromListToRawStream() throws NoSuchFieldException { public void convertFromListToRawStream() throws NoSuchFieldException {
List<String> stream = Arrays.asList("1", "2", "3"); List<String> stream = Arrays.asList("1", "2", "3");
TypeDescriptor streamOfInteger = new TypeDescriptor(Types.class.getField("rawStream")); ; TypeDescriptor streamOfInteger = new TypeDescriptor(Types.class.getField("rawStream")); ;
...@@ -169,7 +175,7 @@ public class StreamConverterTests { ...@@ -169,7 +175,7 @@ public class StreamConverterTests {
new TypeDescriptor(Types.class.getField("arrayOfLongs"))); new TypeDescriptor(Types.class.getField("arrayOfLongs")));
} }
@SuppressWarnings("unused") @SuppressWarnings({ "rawtypes" })
static class Types { static class Types {
public List<String> listOfStrings; public List<String> listOfStrings;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册