Polish StreamConverter(Tests)
This commit is contained in:
parent
fcd60b269e
commit
228d9db4d4
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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<String> 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<Integer, Boolean>() {
|
||||
|
|
@ -142,6 +147,7 @@ public class StreamConverterTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
public void convertFromListToRawStream() throws NoSuchFieldException {
|
||||
List<String> 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<String> listOfStrings;
|
||||
|
|
|
|||
Loading…
Reference in New Issue