Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
3bed6cfc
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,发现更多精彩内容 >>
提交
3bed6cfc
编写于
1月 03, 2014
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Activated through rename to *Tests, and added method call interaction tests
Issue: SPR-7831
上级
640d8cb6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
51 addition
and
32 deletion
+51
-32
spring-expression/src/test/java/org/springframework/expression/spel/ExpressionWithConversionTests.java
...mework/expression/spel/ExpressionWithConversionTests.java
+51
-32
未找到文件。
spring-expression/src/test/java/org/springframework/expression/spel/Expression
TestsUsingCoreConversionService
.java
→
spring-expression/src/test/java/org/springframework/expression/spel/Expression
WithConversionTests
.java
浏览文件 @
3bed6cfc
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
3
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -16,10 +16,6 @@
package
org.springframework.expression.spel
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
...
...
@@ -27,6 +23,7 @@ import java.util.List;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.core.MethodParameter
;
import
org.springframework.core.convert.ConversionService
;
import
org.springframework.core.convert.TypeDescriptor
;
...
...
@@ -36,6 +33,8 @@ import org.springframework.expression.Expression;
import
org.springframework.expression.TypeConverter
;
import
org.springframework.expression.spel.support.StandardEvaluationContext
;
import
static
org
.
junit
.
Assert
.*;
/**
* Expression evaluation where the TypeConverter plugged in is the
* {@link org.springframework.core.convert.support.GenericConversionService}.
...
...
@@ -43,7 +42,7 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
* @author Andy Clement
* @author Dave Syer
*/
public
class
Expression
TestsUsingCoreConversionService
extends
ExpressionTestCase
{
public
class
Expression
WithConversionTests
extends
ExpressionTestCase
{
private
static
List
<
String
>
listOfString
=
new
ArrayList
<
String
>();
private
static
TypeDescriptor
typeDescriptorForListOfString
=
null
;
...
...
@@ -61,8 +60,8 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas
@Before
public
void
setUp
()
throws
Exception
{
Expression
TestsUsingCoreConversionService
.
typeDescriptorForListOfString
=
new
TypeDescriptor
(
ExpressionTestsUsingCoreConversionService
.
class
.
getDeclaredField
(
"listOfString"
));
Expression
TestsUsingCoreConversionService
.
typeDescriptorForListOfInteger
=
new
TypeDescriptor
(
ExpressionTestsUsingCoreConversionService
.
class
.
getDeclaredField
(
"listOfInteger"
));
Expression
WithConversionTests
.
typeDescriptorForListOfString
=
new
TypeDescriptor
(
ExpressionWithConversionTests
.
class
.
getDeclaredField
(
"listOfString"
));
Expression
WithConversionTests
.
typeDescriptorForListOfInteger
=
new
TypeDescriptor
(
ExpressionWithConversionTests
.
class
.
getDeclaredField
(
"listOfInteger"
));
}
...
...
@@ -133,45 +132,37 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas
}
public
static
class
Foo
{
private
Collection
<
Foo
>
foos
;
public
final
String
value
;
public
Foo
(
String
value
)
{
this
.
value
=
value
;
}
public
void
setFoos
(
Collection
<
Foo
>
foos
)
{
this
.
foos
=
foos
;
}
public
Collection
<
Foo
>
getFoos
()
{
return
this
.
foos
;
}
}
@Test
public
void
testConvert
()
{
Foo
root
=
new
Foo
(
"bar"
);
StandardEvaluationContext
context
=
new
StandardEvaluationContext
(
root
);
Collection
<
String
>
foos
=
Collections
.
singletonList
(
"baz"
);
// property access, works
StandardEvaluationContext
context
=
new
StandardEvaluationContext
(
root
);
// property access
Expression
expression
=
parser
.
parseExpression
(
"foos"
);
expression
.
setValue
(
context
,
foos
);
Foo
baz
=
root
.
getFoos
().
iterator
().
next
();
assertEquals
(
"baz"
,
baz
.
value
);
// method call
, fails (ClassCastException)
// method call
expression
=
parser
.
parseExpression
(
"setFoos(#foos)"
);
context
.
setVariable
(
"foos"
,
foos
);
expression
.
getValue
(
context
);
baz
=
root
.
getFoos
().
iterator
().
next
();
assertEquals
(
"baz"
,
baz
.
value
);
// method call with result from method call
expression
=
parser
.
parseExpression
(
"setFoos(getFoosAsStrings())"
);
expression
.
getValue
(
context
);
baz
=
root
.
getFoos
().
iterator
().
next
();
assertEquals
(
"baz"
,
baz
.
value
);
// method call with result from method call
expression
=
parser
.
parseExpression
(
"setFoos(getFoosAsObjects())"
);
expression
.
getValue
(
context
);
baz
=
root
.
getFoos
().
iterator
().
next
();
assertEquals
(
"baz"
,
baz
.
value
);
}
...
...
@@ -193,4 +184,32 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas
}
}
public
static
class
Foo
{
public
final
String
value
;
private
Collection
<
Foo
>
foos
;
public
Foo
(
String
value
)
{
this
.
value
=
value
;
}
public
void
setFoos
(
Collection
<
Foo
>
foos
)
{
this
.
foos
=
foos
;
}
public
Collection
<
Foo
>
getFoos
()
{
return
this
.
foos
;
}
public
Collection
<
String
>
getFoosAsStrings
()
{
return
Collections
.
singletonList
(
"baz"
);
}
public
Collection
<?>
getFoosAsObjects
()
{
return
Collections
.
singletonList
(
"baz"
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录