Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
64bd8b7f
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
64bd8b7f
编写于
12月 18, 2015
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polishing
上级
387c8a81
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
103 addition
and
63 deletion
+103
-63
spring-core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionConverterTests.java
...convert/support/CollectionToCollectionConverterTests.java
+20
-20
spring-core/src/test/java/org/springframework/core/convert/support/DefaultConversionServiceTests.java
...k/core/convert/support/DefaultConversionServiceTests.java
+22
-17
spring-core/src/test/java/org/springframework/core/convert/support/MapToMapConverterTests.java
...ramework/core/convert/support/MapToMapConverterTests.java
+46
-20
spring-core/src/test/java/org/springframework/core/convert/support/StreamConverterTests.java
...gframework/core/convert/support/StreamConverterTests.java
+15
-6
未找到文件。
spring-core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionConverterTests.java
浏览文件 @
64bd8b7f
...
...
@@ -262,6 +262,25 @@ public class CollectionToCollectionConverterTests {
}
public
ArrayList
<
Integer
>
scalarListTarget
;
public
List
<
Integer
>
emptyListTarget
;
public
LinkedList
<
Integer
>
emptyListDifferentTarget
;
public
List
<
List
<
List
<
Integer
>>>
objectToCollection
;
public
List
<
String
>
strings
;
public
List
<?>
list
=
Collections
.
emptyList
();
public
Collection
<?>
wildcardCollection
=
Collections
.
emptyList
();
public
List
<
Resource
>
resources
;
public
EnumSet
<
MyEnum
>
enumSet
;
public
static
abstract
class
BaseResource
implements
Resource
{
@Override
...
...
@@ -330,25 +349,6 @@ public class CollectionToCollectionConverterTests {
}
public
static
enum
MyEnum
{
A
,
B
,
C
}
public
ArrayList
<
Integer
>
scalarListTarget
;
public
List
<
Integer
>
emptyListTarget
;
public
LinkedList
<
Integer
>
emptyListDifferentTarget
;
public
List
<
List
<
List
<
Integer
>>>
objectToCollection
;
public
List
<
String
>
strings
;
public
List
<?>
list
=
Collections
.
emptyList
();
public
Collection
<?>
wildcardCollection
=
Collections
.
emptyList
();
public
List
<
Resource
>
resources
;
public
EnumSet
<
MyEnum
>
enumSet
;
public
enum
MyEnum
{
A
,
B
,
C
}
}
spring-core/src/test/java/org/springframework/core/convert/support/DefaultConversionServiceTests.java
浏览文件 @
64bd8b7f
...
...
@@ -313,7 +313,7 @@ public class DefaultConversionServiceTests {
@Test
public
void
convertArrayToCollectionInterface
()
{
List
<?>
result
=
conversionService
.
convert
(
new
String
[]
{
"1"
,
"2"
,
"3"
},
List
.
class
);
List
<?>
result
=
conversionService
.
convert
(
new
String
[]
{
"1"
,
"2"
,
"3"
},
List
.
class
);
assertEquals
(
"1"
,
result
.
get
(
0
));
assertEquals
(
"2"
,
result
.
get
(
1
));
assertEquals
(
"3"
,
result
.
get
(
2
));
...
...
@@ -322,7 +322,7 @@ public class DefaultConversionServiceTests {
@Test
public
void
convertArrayToCollectionGenericTypeConversion
()
throws
Exception
{
@SuppressWarnings
(
"unchecked"
)
List
<
Integer
>
result
=
(
List
<
Integer
>)
conversionService
.
convert
(
new
String
[]
{
"1"
,
"2"
,
"3"
},
TypeDescriptor
List
<
Integer
>
result
=
(
List
<
Integer
>)
conversionService
.
convert
(
new
String
[]
{
"1"
,
"2"
,
"3"
},
TypeDescriptor
.
valueOf
(
String
[].
class
),
new
TypeDescriptor
(
getClass
().
getDeclaredField
(
"genericList"
)));
assertEquals
(
new
Integer
(
"1"
),
result
.
get
(
0
));
assertEquals
(
new
Integer
(
"2"
),
result
.
get
(
1
));
...
...
@@ -344,7 +344,7 @@ public class DefaultConversionServiceTests {
ConverterRegistry
registry
=
(
conversionService
);
registry
.
addConverter
(
new
ColorConverter
());
@SuppressWarnings
(
"unchecked"
)
List
<
Color
>
colors
=
(
List
<
Color
>)
conversionService
.
convert
(
new
String
[]
{
"ffffff"
,
"#000000"
},
List
<
Color
>
colors
=
(
List
<
Color
>)
conversionService
.
convert
(
new
String
[]
{
"ffffff"
,
"#000000"
},
TypeDescriptor
.
valueOf
(
String
[].
class
),
new
TypeDescriptor
(
new
MethodParameter
(
getClass
().
getMethod
(
"handlerMethod"
,
List
.
class
),
0
)));
assertEquals
(
2
,
colors
.
size
());
...
...
@@ -354,7 +354,7 @@ public class DefaultConversionServiceTests {
@Test
public
void
convertArrayToCollectionImpl
()
{
LinkedList
<?>
result
=
conversionService
.
convert
(
new
String
[]
{
"1"
,
"2"
,
"3"
},
LinkedList
.
class
);
LinkedList
<?>
result
=
conversionService
.
convert
(
new
String
[]
{
"1"
,
"2"
,
"3"
},
LinkedList
.
class
);
assertEquals
(
"1"
,
result
.
get
(
0
));
assertEquals
(
"2"
,
result
.
get
(
1
));
assertEquals
(
"3"
,
result
.
get
(
2
));
...
...
@@ -371,13 +371,13 @@ public class DefaultConversionServiceTests {
@Test
public
void
convertArrayToString
()
{
String
result
=
conversionService
.
convert
(
new
String
[]
{
"1"
,
"2"
,
"3"
},
String
.
class
);
String
result
=
conversionService
.
convert
(
new
String
[]
{
"1"
,
"2"
,
"3"
},
String
.
class
);
assertEquals
(
"1,2,3"
,
result
);
}
@Test
public
void
convertArrayToStringWithElementConversion
()
{
String
result
=
conversionService
.
convert
(
new
Integer
[]
{
1
,
2
,
3
},
String
.
class
);
String
result
=
conversionService
.
convert
(
new
Integer
[]
{
1
,
2
,
3
},
String
.
class
);
assertEquals
(
"1,2,3"
,
result
);
}
...
...
@@ -422,21 +422,21 @@ public class DefaultConversionServiceTests {
@Test
public
void
convertArrayToObject
()
{
Object
[]
array
=
new
Object
[]
{
3L
};
Object
[]
array
=
new
Object
[]
{
3L
};
Object
result
=
conversionService
.
convert
(
array
,
Long
.
class
);
assertEquals
(
3L
,
result
);
}
@Test
public
void
convertArrayToObjectWithElementConversion
()
{
String
[]
array
=
new
String
[]
{
"3"
};
String
[]
array
=
new
String
[]
{
"3"
};
Integer
result
=
conversionService
.
convert
(
array
,
Integer
.
class
);
assertEquals
(
new
Integer
(
3
),
result
);
}
@Test
public
void
convertArrayToObjectAssignableTargetType
()
{
Long
[]
array
=
new
Long
[]
{
3L
};
Long
[]
array
=
new
Long
[]
{
3L
};
Long
[]
result
=
(
Long
[])
conversionService
.
convert
(
array
,
Object
.
class
);
assertArrayEquals
(
array
,
result
);
}
...
...
@@ -849,14 +849,14 @@ public class DefaultConversionServiceTests {
}
});
char
[]
converted
=
conversionService
.
convert
(
"abc"
,
char
[].
class
);
assertThat
(
converted
,
equalTo
(
new
char
[]
{
'a'
,
'b'
,
'c'
}));
assertThat
(
converted
,
equalTo
(
new
char
[]
{
'a'
,
'b'
,
'c'
}));
}
@Test
@SuppressWarnings
(
"unchecked"
)
public
void
multidimensionalArrayToListConversionShouldConvertEntriesCorrectly
()
{
String
[][]
grid
=
new
String
[][]
{
new
String
[]
{
"1"
,
"2"
,
"3"
,
"4"
},
new
String
[]
{
"5"
,
"6"
,
"7"
,
"8"
},
new
String
[]
{
"9"
,
"10"
,
"11"
,
"12"
}
};
String
[][]
grid
=
new
String
[][]
{
new
String
[]
{
"1"
,
"2"
,
"3"
,
"4"
},
new
String
[]
{
"5"
,
"6"
,
"7"
,
"8"
},
new
String
[]
{
"9"
,
"10"
,
"11"
,
"12"
}
};
List
<
String
[]>
converted
=
conversionService
.
convert
(
grid
,
List
.
class
);
String
[][]
convertedBack
=
conversionService
.
convert
(
converted
,
String
[][].
class
);
assertArrayEquals
(
grid
,
convertedBack
);
...
...
@@ -865,16 +865,15 @@ public class DefaultConversionServiceTests {
@Test
public
void
convertCannotOptimizeArray
()
{
conversionService
.
addConverter
(
new
Converter
<
Byte
,
Byte
>()
{
@Override
public
Byte
convert
(
Byte
source
)
{
return
(
byte
)
(
source
+
1
);
}
});
byte
[]
byteArray
=
new
byte
[]
{
1
,
2
,
3
};
byte
[]
byteArray
=
new
byte
[]
{
1
,
2
,
3
};
byte
[]
converted
=
conversionService
.
convert
(
byteArray
,
byte
[].
class
);
assertNotSame
(
byteArray
,
converted
);
assertTrue
(
Arrays
.
equals
(
new
byte
[]
{
2
,
3
,
4
},
converted
));
assertTrue
(
Arrays
.
equals
(
new
byte
[]
{
2
,
3
,
4
},
converted
));
}
@Test
...
...
@@ -938,6 +937,7 @@ public class DefaultConversionServiceTests {
public
enum
Foo
{
BAR
,
BAZ
}
...
...
@@ -964,7 +964,12 @@ public class DefaultConversionServiceTests {
public
class
ColorConverter
implements
Converter
<
String
,
Color
>
{
@Override
public
Color
convert
(
String
source
)
{
if
(!
source
.
startsWith
(
"#"
))
source
=
"#"
+
source
;
return
Color
.
decode
(
source
);
}
public
Color
convert
(
String
source
)
{
if
(!
source
.
startsWith
(
"#"
))
{
source
=
"#"
+
source
;
}
return
Color
.
decode
(
source
);
}
}
...
...
@@ -1031,8 +1036,8 @@ public class DefaultConversionServiceTests {
private
static
class
SSN
{
static
int
constructorCount
=
0
;
static
int
toStringCount
=
0
;
static
int
toStringCount
=
0
;
static
void
reset
()
{
constructorCount
=
0
;
...
...
spring-core/src/test/java/org/springframework/core/convert/support/MapToMapConverterTests.java
浏览文件 @
64bd8b7f
...
...
@@ -36,9 +36,14 @@ import org.springframework.util.MultiValueMap;
import
static
org
.
hamcrest
.
Matchers
.*;
import
static
org
.
junit
.
Assert
.*;
/**
* @author Keith Donald
* @author Phil Webb
* @author Juergen Hoeller
*/
public
class
MapToMapConverterTests
{
private
GenericConversionService
conversionService
=
new
GenericConversionService
();
private
final
GenericConversionService
conversionService
=
new
GenericConversionService
();
@Before
...
...
@@ -54,12 +59,15 @@ public class MapToMapConverterTests {
map
.
put
(
"2"
,
"37"
);
TypeDescriptor
sourceType
=
TypeDescriptor
.
forObject
(
map
);
TypeDescriptor
targetType
=
new
TypeDescriptor
(
getClass
().
getField
(
"scalarMapTarget"
));
assertTrue
(
conversionService
.
canConvert
(
sourceType
,
targetType
));
try
{
conversionService
.
convert
(
map
,
sourceType
,
targetType
);
}
catch
(
ConversionFailedException
e
)
{
assertTrue
(
e
.
getCause
()
instanceof
ConverterNotFoundException
);
}
catch
(
ConversionFailedException
ex
)
{
assertTrue
(
ex
.
getCause
()
instanceof
ConverterNotFoundException
);
}
conversionService
.
addConverterFactory
(
new
StringToNumberConverterFactory
());
assertTrue
(
conversionService
.
canConvert
(
sourceType
,
targetType
));
@SuppressWarnings
(
"unchecked"
)
...
...
@@ -74,6 +82,7 @@ public class MapToMapConverterTests {
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
map
.
put
(
"1"
,
"9"
);
map
.
put
(
"2"
,
"37"
);
assertTrue
(
conversionService
.
canConvert
(
Map
.
class
,
Map
.
class
));
assertSame
(
map
,
conversionService
.
convert
(
map
,
Map
.
class
));
}
...
...
@@ -85,12 +94,15 @@ public class MapToMapConverterTests {
map
.
put
(
"2"
,
"37"
);
TypeDescriptor
sourceType
=
new
TypeDescriptor
(
getClass
().
getField
(
"notGenericMapSource"
));
TypeDescriptor
targetType
=
new
TypeDescriptor
(
getClass
().
getField
(
"scalarMapTarget"
));
assertTrue
(
conversionService
.
canConvert
(
sourceType
,
targetType
));
try
{
conversionService
.
convert
(
map
,
sourceType
,
targetType
);
}
catch
(
ConversionFailedException
e
)
{
assertTrue
(
e
.
getCause
()
instanceof
ConverterNotFoundException
);
}
catch
(
ConversionFailedException
ex
)
{
assertTrue
(
ex
.
getCause
()
instanceof
ConverterNotFoundException
);
}
conversionService
.
addConverterFactory
(
new
StringToNumberConverterFactory
());
assertTrue
(
conversionService
.
canConvert
(
sourceType
,
targetType
));
@SuppressWarnings
(
"unchecked"
)
...
...
@@ -107,12 +119,15 @@ public class MapToMapConverterTests {
map
.
put
(
"2"
,
Arrays
.
asList
(
"37"
,
"23"
));
TypeDescriptor
sourceType
=
TypeDescriptor
.
forObject
(
map
);
TypeDescriptor
targetType
=
new
TypeDescriptor
(
getClass
().
getField
(
"collectionMapTarget"
));
assertTrue
(
conversionService
.
canConvert
(
sourceType
,
targetType
));
try
{
conversionService
.
convert
(
map
,
sourceType
,
targetType
);
}
catch
(
ConversionFailedException
e
)
{
assertTrue
(
e
.
getCause
()
instanceof
ConverterNotFoundException
);
}
catch
(
ConversionFailedException
ex
)
{
assertTrue
(
ex
.
getCause
()
instanceof
ConverterNotFoundException
);
}
conversionService
.
addConverter
(
new
CollectionToCollectionConverter
(
conversionService
));
conversionService
.
addConverterFactory
(
new
StringToNumberConverterFactory
());
assertTrue
(
conversionService
.
canConvert
(
sourceType
,
targetType
));
...
...
@@ -130,6 +145,7 @@ public class MapToMapConverterTests {
map
.
put
(
"2"
,
Arrays
.
asList
(
"37"
,
"23"
));
TypeDescriptor
sourceType
=
new
TypeDescriptor
(
getClass
().
getField
(
"sourceCollectionMapTarget"
));
TypeDescriptor
targetType
=
new
TypeDescriptor
(
getClass
().
getField
(
"collectionMapTarget"
));
assertFalse
(
conversionService
.
canConvert
(
sourceType
,
targetType
));
try
{
conversionService
.
convert
(
map
,
sourceType
,
targetType
);
...
...
@@ -138,6 +154,7 @@ public class MapToMapConverterTests {
catch
(
ConverterNotFoundException
ex
)
{
// expected
}
conversionService
.
addConverter
(
new
CollectionToCollectionConverter
(
conversionService
));
conversionService
.
addConverterFactory
(
new
StringToNumberConverterFactory
());
assertTrue
(
conversionService
.
canConvert
(
sourceType
,
targetType
));
...
...
@@ -153,6 +170,7 @@ public class MapToMapConverterTests {
Map
<
String
,
List
<
String
>>
map
=
new
HashMap
<
String
,
List
<
String
>>();
map
.
put
(
"1"
,
Arrays
.
asList
(
"9"
,
"12"
));
map
.
put
(
"2"
,
Arrays
.
asList
(
"37"
,
"23"
));
assertTrue
(
conversionService
.
canConvert
(
Map
.
class
,
Map
.
class
));
assertSame
(
map
,
conversionService
.
convert
(
map
,
Map
.
class
));
}
...
...
@@ -164,6 +182,7 @@ public class MapToMapConverterTests {
map
.
put
(
"2"
,
Arrays
.
asList
(
"37"
,
"23"
));
conversionService
.
addConverter
(
new
CollectionToCollectionConverter
(
conversionService
));
conversionService
.
addConverter
(
new
CollectionToObjectConverter
(
conversionService
));
assertTrue
(
conversionService
.
canConvert
(
Map
.
class
,
Map
.
class
));
assertSame
(
map
,
conversionService
.
convert
(
map
,
Map
.
class
));
}
...
...
@@ -173,6 +192,7 @@ public class MapToMapConverterTests {
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
TypeDescriptor
sourceType
=
TypeDescriptor
.
forObject
(
map
);
TypeDescriptor
targetType
=
new
TypeDescriptor
(
getClass
().
getField
(
"emptyMapTarget"
));
assertTrue
(
conversionService
.
canConvert
(
sourceType
,
targetType
));
assertSame
(
map
,
conversionService
.
convert
(
map
,
sourceType
,
targetType
));
}
...
...
@@ -180,6 +200,7 @@ public class MapToMapConverterTests {
@Test
public
void
emptyMapNoTargetGenericInfo
()
throws
Exception
{
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
assertTrue
(
conversionService
.
canConvert
(
Map
.
class
,
Map
.
class
));
assertSame
(
map
,
conversionService
.
convert
(
map
,
Map
.
class
));
}
...
...
@@ -189,6 +210,7 @@ public class MapToMapConverterTests {
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
TypeDescriptor
sourceType
=
TypeDescriptor
.
forObject
(
map
);
TypeDescriptor
targetType
=
new
TypeDescriptor
(
getClass
().
getField
(
"emptyMapDifferentTarget"
));
assertTrue
(
conversionService
.
canConvert
(
sourceType
,
targetType
));
@SuppressWarnings
(
"unchecked"
)
LinkedHashMap
<
String
,
String
>
result
=
(
LinkedHashMap
<
String
,
String
>)
conversionService
.
convert
(
map
,
sourceType
,
targetType
);
...
...
@@ -205,6 +227,7 @@ public class MapToMapConverterTests {
TypeDescriptor
.
valueOf
(
String
.
class
),
TypeDescriptor
.
valueOf
(
Integer
.
class
));
TypeDescriptor
targetType
=
TypeDescriptor
.
map
(
NoDefaultConstructorMap
.
class
,
TypeDescriptor
.
valueOf
(
String
.
class
),
TypeDescriptor
.
valueOf
(
Integer
.
class
));
assertTrue
(
conversionService
.
canConvert
(
sourceType
,
targetType
));
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
Integer
>
result
=
(
Map
<
String
,
Integer
>)
conversionService
.
convert
(
map
,
sourceType
,
targetType
);
...
...
@@ -220,6 +243,7 @@ public class MapToMapConverterTests {
source
.
put
(
"a"
,
Arrays
.
asList
(
1
,
2
,
3
));
source
.
put
(
"b"
,
Arrays
.
asList
(
4
,
5
,
6
));
TypeDescriptor
targetType
=
new
TypeDescriptor
(
getClass
().
getField
(
"multiValueMapTarget"
));
MultiValueMap
<
String
,
String
>
converted
=
(
MultiValueMap
<
String
,
String
>)
conversionService
.
convert
(
source
,
targetType
);
assertThat
(
converted
.
size
(),
equalTo
(
2
));
assertThat
(
converted
.
get
(
"a"
),
equalTo
(
Arrays
.
asList
(
"1"
,
"2"
,
"3"
)));
...
...
@@ -234,6 +258,7 @@ public class MapToMapConverterTests {
source
.
put
(
"a"
,
1
);
source
.
put
(
"b"
,
2
);
TypeDescriptor
targetType
=
new
TypeDescriptor
(
getClass
().
getField
(
"multiValueMapTarget"
));
MultiValueMap
<
String
,
String
>
converted
=
(
MultiValueMap
<
String
,
String
>)
conversionService
.
convert
(
source
,
targetType
);
assertThat
(
converted
.
size
(),
equalTo
(
2
));
assertThat
(
converted
.
get
(
"a"
),
equalTo
(
Arrays
.
asList
(
"1"
)));
...
...
@@ -249,23 +274,12 @@ public class MapToMapConverterTests {
EnumMap
<
MyEnum
,
Integer
>
result
=
new
EnumMap
<
MyEnum
,
Integer
>(
MyEnum
.
class
);
result
.
put
(
MyEnum
.
A
,
1
);
result
.
put
(
MyEnum
.
C
,
2
);
assertEquals
(
result
,
conversionService
.
convert
(
source
,
TypeDescriptor
.
forObject
(
source
),
new
TypeDescriptor
(
getClass
().
getField
(
"enumMap"
))));
}
@SuppressWarnings
(
"serial"
)
public
static
class
NoDefaultConstructorMap
<
K
,
V
>
extends
HashMap
<
K
,
V
>
{
public
NoDefaultConstructorMap
(
Map
<?
extends
K
,
?
extends
V
>
map
)
{
super
(
map
);
}
assertEquals
(
result
,
conversionService
.
convert
(
source
,
TypeDescriptor
.
forObject
(
source
),
new
TypeDescriptor
(
getClass
().
getField
(
"enumMap"
))));
}
public
static
enum
MyEnum
{
A
,
B
,
C
}
public
Map
<
Integer
,
Integer
>
scalarMapTarget
;
public
Map
<
Integer
,
List
<
Integer
>>
collectionMapTarget
;
...
...
@@ -283,4 +297,16 @@ public class MapToMapConverterTests {
public
EnumMap
<
MyEnum
,
Integer
>
enumMap
;
@SuppressWarnings
(
"serial"
)
public
static
class
NoDefaultConstructorMap
<
K
,
V
>
extends
HashMap
<
K
,
V
>
{
public
NoDefaultConstructorMap
(
Map
<?
extends
K
,
?
extends
V
>
map
)
{
super
(
map
);
}
}
public
enum
MyEnum
{
A
,
B
,
C
}
}
spring-core/src/test/java/org/springframework/core/convert/support/StreamConverterTests.java
浏览文件 @
64bd8b7f
...
...
@@ -49,6 +49,7 @@ public class StreamConverterTests {
private
final
StreamConverter
streamConverter
=
new
StreamConverter
(
this
.
conversionService
);
@Before
public
void
setup
()
{
this
.
conversionService
.
addConverter
(
new
CollectionToCollectionConverter
(
this
.
conversionService
));
...
...
@@ -57,13 +58,15 @@ public class StreamConverterTests {
this
.
conversionService
.
addConverter
(
this
.
streamConverter
);
}
@Test
public
void
convertFromStreamToList
()
throws
NoSuchFieldException
{
this
.
conversionService
.
addConverter
(
Number
.
class
,
String
.
class
,
new
ObjectToStringConverter
());
Stream
<
Integer
>
stream
=
Arrays
.
asList
(
1
,
2
,
3
).
stream
();
TypeDescriptor
listOfStrings
=
new
TypeDescriptor
(
Types
.
class
.
getField
(
"listOfStrings"
));
;
Object
result
=
this
.
conversionService
.
convert
(
stream
,
listOfStrings
);
assertNotNull
(
"converted object must not be null"
,
result
);
assertNotNull
(
"Converted object must not be null"
,
result
);
assertTrue
(
"Converted object must be a list"
,
result
instanceof
List
);
@SuppressWarnings
(
"unchecked"
)
List
<
String
>
content
=
(
List
<
String
>)
result
;
...
...
@@ -79,7 +82,8 @@ public class StreamConverterTests {
Stream
<
Integer
>
stream
=
Arrays
.
asList
(
1
,
2
,
3
).
stream
();
TypeDescriptor
arrayOfLongs
=
new
TypeDescriptor
(
Types
.
class
.
getField
(
"arrayOfLongs"
));
;
Object
result
=
this
.
conversionService
.
convert
(
stream
,
arrayOfLongs
);
assertNotNull
(
"converted object must not be null"
,
result
);
assertNotNull
(
"Converted object must not be null"
,
result
);
assertTrue
(
"Converted object must be an array"
,
result
.
getClass
().
isArray
());
Long
[]
content
=
(
Long
[])
result
;
assertEquals
(
Long
.
valueOf
(
1L
),
content
[
0
]);
...
...
@@ -93,7 +97,8 @@ public class StreamConverterTests {
Stream
<
Integer
>
stream
=
Arrays
.
asList
(
1
,
2
,
3
).
stream
();
TypeDescriptor
listOfStrings
=
new
TypeDescriptor
(
Types
.
class
.
getField
(
"rawList"
));
;
Object
result
=
this
.
conversionService
.
convert
(
stream
,
listOfStrings
);
assertNotNull
(
"converted object must not be null"
,
result
);
assertNotNull
(
"Converted object must not be null"
,
result
);
assertTrue
(
"Converted object must be a list"
,
result
instanceof
List
);
@SuppressWarnings
(
"unchecked"
)
List
<
Object
>
content
=
(
List
<
Object
>)
result
;
...
...
@@ -120,7 +125,8 @@ public class StreamConverterTests {
List
<
String
>
stream
=
Arrays
.
asList
(
"1"
,
"2"
,
"3"
);
TypeDescriptor
streamOfInteger
=
new
TypeDescriptor
(
Types
.
class
.
getField
(
"streamOfIntegers"
));
;
Object
result
=
this
.
conversionService
.
convert
(
stream
,
streamOfInteger
);
assertNotNull
(
"converted object must not be null"
,
result
);
assertNotNull
(
"Converted object must not be null"
,
result
);
assertTrue
(
"Converted object must be a stream"
,
result
instanceof
Stream
);
@SuppressWarnings
(
"unchecked"
)
Stream
<
Integer
>
content
=
(
Stream
<
Integer
>)
result
;
...
...
@@ -139,7 +145,8 @@ public class StreamConverterTests {
});
TypeDescriptor
streamOfBoolean
=
new
TypeDescriptor
(
Types
.
class
.
getField
(
"streamOfBooleans"
));
;
Object
result
=
this
.
conversionService
.
convert
(
stream
,
streamOfBoolean
);
assertNotNull
(
"converted object must not be null"
,
result
);
assertNotNull
(
"Converted object must not be null"
,
result
);
assertTrue
(
"Converted object must be a stream"
,
result
instanceof
Stream
);
@SuppressWarnings
(
"unchecked"
)
Stream
<
Boolean
>
content
=
(
Stream
<
Boolean
>)
result
;
...
...
@@ -152,7 +159,8 @@ public class StreamConverterTests {
List
<
String
>
stream
=
Arrays
.
asList
(
"1"
,
"2"
,
"3"
);
TypeDescriptor
streamOfInteger
=
new
TypeDescriptor
(
Types
.
class
.
getField
(
"rawStream"
));
;
Object
result
=
this
.
conversionService
.
convert
(
stream
,
streamOfInteger
);
assertNotNull
(
"converted object must not be null"
,
result
);
assertNotNull
(
"Converted object must not be null"
,
result
);
assertTrue
(
"Converted object must be a stream"
,
result
instanceof
Stream
);
@SuppressWarnings
(
"unchecked"
)
Stream
<
Object
>
content
=
(
Stream
<
Object
>)
result
;
...
...
@@ -175,6 +183,7 @@ public class StreamConverterTests {
new
TypeDescriptor
(
Types
.
class
.
getField
(
"arrayOfLongs"
)));
}
@SuppressWarnings
({
"rawtypes"
})
static
class
Types
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录