Skip to content

Commit 228d9db

Browse files
committed
Polish StreamConverter(Tests)
1 parent fcd60b2 commit 228d9db

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

spring-core/src/main/java/org/springframework/core/convert/support/StreamConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.springframework.lang.UsesJava8;
3030

3131
/**
32-
* Convert a {@link Stream} to an from a collection or array, converting the
32+
* Converts a {@link Stream} to and from a collection or array, converting the
3333
* element type if necessary.
3434
*
3535
* @author Stephane Nicoll
@@ -77,7 +77,7 @@ public boolean matchesFromStream(TypeDescriptor elementType, TypeDescriptor targ
7777

7878
/**
7979
* Validate that the specified {@code sourceType} can be converted to a {@link Collection} of
80-
* type type of the stream elements
80+
* the type of the stream elements.
8181
* @param elementType the type of the stream elements
8282
* @param sourceType the type to convert from
8383
*/

spring-core/src/test/java/org/springframework/core/convert/support/StreamConverterTests.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,23 @@
3434
import static org.hamcrest.core.Is.is;
3535
import static org.junit.Assert.*;
3636

37+
/**
38+
* Tests for {@link StreamConverter}.
39+
*
40+
* @author Stephane Nicoll
41+
* @since 4.2
42+
*/
3743
public class StreamConverterTests {
3844

3945
@Rule
4046
public final ExpectedException thrown = ExpectedException.none();
4147

42-
private GenericConversionService conversionService;
48+
private final GenericConversionService conversionService = new GenericConversionService();
4349

44-
private StreamConverter streamConverter;
50+
private final StreamConverter streamConverter = new StreamConverter(this.conversionService);
4551

4652
@Before
4753
public void setup() {
48-
this.conversionService = new GenericConversionService();
49-
this.streamConverter = new StreamConverter(this.conversionService);
50-
5154
this.conversionService.addConverter(new CollectionToCollectionConverter(this.conversionService));
5255
this.conversionService.addConverter(new ArrayToCollectionConverter(this.conversionService));
5356
this.conversionService.addConverter(new CollectionToArrayConverter(this.conversionService));
@@ -111,6 +114,7 @@ public void convertFromStreamToArrayNoConverter() throws NoSuchFieldException {
111114
}
112115

113116
@Test
117+
@SuppressWarnings("resource")
114118
public void convertFromListToStream() throws NoSuchFieldException {
115119
this.conversionService.addConverterFactory(new StringToNumberConverterFactory());
116120
List<String> stream = Arrays.asList("1", "2", "3");
@@ -124,6 +128,7 @@ public void convertFromListToStream() throws NoSuchFieldException {
124128
}
125129

126130
@Test
131+
@SuppressWarnings("resource")
127132
public void convertFromArrayToStream() throws NoSuchFieldException {
128133
Integer[] stream = new Integer[] {1, 0, 1};
129134
this.conversionService.addConverter(new Converter<Integer, Boolean>() {
@@ -142,6 +147,7 @@ public Boolean convert(Integer source) {
142147
}
143148

144149
@Test
150+
@SuppressWarnings("resource")
145151
public void convertFromListToRawStream() throws NoSuchFieldException {
146152
List<String> stream = Arrays.asList("1", "2", "3");
147153
TypeDescriptor streamOfInteger = new TypeDescriptor(Types.class.getField("rawStream")); ;
@@ -169,7 +175,7 @@ public void shouldFailToConvertIfNoStream() throws NoSuchFieldException {
169175
new TypeDescriptor(Types.class.getField("arrayOfLongs")));
170176
}
171177

172-
@SuppressWarnings("unused")
178+
@SuppressWarnings({ "rawtypes" })
173179
static class Types {
174180

175181
public List<String> listOfStrings;

0 commit comments

Comments
 (0)