Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
d2503340
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,体验更适合开发者的 AI 搜索 >>
提交
d2503340
编写于
8月 14, 2015
作者:
S
Sam Brannen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish assertion msgs in JsonPathExpectationsHelper
上级
af8d9eab
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
11 addition
and
11 deletion
+11
-11
spring-test/src/main/java/org/springframework/test/util/JsonPathExpectationsHelper.java
...springframework/test/util/JsonPathExpectationsHelper.java
+10
-10
spring-test/src/test/java/org/springframework/test/util/JsonPathExpectationsHelperTests.java
...gframework/test/util/JsonPathExpectationsHelperTests.java
+1
-1
未找到文件。
spring-test/src/main/java/org/springframework/test/util/JsonPathExpectationsHelper.java
浏览文件 @
d2503340
...
...
@@ -113,7 +113,7 @@ public class JsonPathExpectationsHelper {
@SuppressWarnings
(
"rawtypes"
)
List
actualValueList
=
(
List
)
actualValue
;
if
(
actualValueList
.
isEmpty
())
{
fail
(
"No matching value
for
JSON path \""
+
this
.
expression
+
"\""
);
fail
(
"No matching value
at
JSON path \""
+
this
.
expression
+
"\""
);
}
if
(
actualValueList
.
size
()
!=
1
)
{
fail
(
"Got a list of values "
+
actualValue
+
" instead of the expected single value "
+
expectedValue
);
...
...
@@ -121,7 +121,7 @@ public class JsonPathExpectationsHelper {
actualValue
=
actualValueList
.
get
(
0
);
}
else
if
(
actualValue
!=
null
&&
expectedValue
!=
null
)
{
assertEquals
(
"
For
JSON path \""
+
this
.
expression
+
"\", type of value"
,
assertEquals
(
"
At
JSON path \""
+
this
.
expression
+
"\", type of value"
,
expectedValue
.
getClass
().
getName
(),
actualValue
.
getClass
().
getName
());
}
assertEquals
(
"JSON path \""
+
this
.
expression
+
"\""
,
expectedValue
,
actualValue
);
...
...
@@ -135,7 +135,7 @@ public class JsonPathExpectationsHelper {
*/
public
void
assertValueIsString
(
String
content
)
throws
ParseException
{
Object
value
=
assertExistsAndReturn
(
content
);
String
reason
=
"Expected
string at JSON path \""
+
this
.
expression
+
"\" but found
"
+
value
;
String
reason
=
"Expected
a string at JSON path \""
+
this
.
expression
+
"\" but found:
"
+
value
;
assertThat
(
reason
,
value
,
instanceOf
(
String
.
class
));
}
...
...
@@ -147,7 +147,7 @@ public class JsonPathExpectationsHelper {
*/
public
void
assertValueIsBoolean
(
String
content
)
throws
ParseException
{
Object
value
=
assertExistsAndReturn
(
content
);
String
reason
=
"Expected
boolean at JSON path \""
+
this
.
expression
+
"\" but found
"
+
value
;
String
reason
=
"Expected
a boolean at JSON path \""
+
this
.
expression
+
"\" but found:
"
+
value
;
assertThat
(
reason
,
value
,
instanceOf
(
Boolean
.
class
));
}
...
...
@@ -159,7 +159,7 @@ public class JsonPathExpectationsHelper {
*/
public
void
assertValueIsNumber
(
String
content
)
throws
ParseException
{
Object
value
=
assertExistsAndReturn
(
content
);
String
reason
=
"Expected
number at JSON path \""
+
this
.
expression
+
"\" but found
"
+
value
;
String
reason
=
"Expected
a number at JSON path \""
+
this
.
expression
+
"\" but found:
"
+
value
;
assertThat
(
reason
,
value
,
instanceOf
(
Number
.
class
));
}
...
...
@@ -170,7 +170,7 @@ public class JsonPathExpectationsHelper {
*/
public
void
assertValueIsArray
(
String
content
)
throws
ParseException
{
Object
value
=
assertExistsAndReturn
(
content
);
String
reason
=
"Expected a
rray for JSON path \""
+
this
.
expression
+
"\" but found
"
+
value
;
String
reason
=
"Expected a
n array at JSON path \""
+
this
.
expression
+
"\" but found:
"
+
value
;
assertTrue
(
reason
,
value
instanceof
List
);
}
...
...
@@ -182,7 +182,7 @@ public class JsonPathExpectationsHelper {
*/
public
void
assertValueIsMap
(
String
content
)
throws
ParseException
{
Object
value
=
assertExistsAndReturn
(
content
);
String
reason
=
"Expected
map at JSON path \""
+
this
.
expression
+
"\" but found
"
+
value
;
String
reason
=
"Expected
a map at JSON path \""
+
this
.
expression
+
"\" but found:
"
+
value
;
assertThat
(
reason
,
value
,
instanceOf
(
Map
.
class
));
}
...
...
@@ -209,7 +209,7 @@ public class JsonPathExpectationsHelper {
catch
(
AssertionError
ex
)
{
return
;
}
String
reason
=
String
.
format
(
"Expected no value for JSON path: %s but found: %s"
,
this
.
expression
,
value
)
;
String
reason
=
"Expected no value at JSON path \""
+
this
.
expression
+
"\" but found: "
+
value
;
if
(
List
.
class
.
isInstance
(
value
))
{
assertTrue
(
reason
,
((
List
<?>)
value
).
isEmpty
());
}
...
...
@@ -219,7 +219,7 @@ public class JsonPathExpectationsHelper {
}
private
Object
evaluateJsonPath
(
String
content
)
throws
ParseException
{
String
message
=
"No value
for
JSON path \""
+
this
.
expression
+
"\", exception: "
;
String
message
=
"No value
at
JSON path \""
+
this
.
expression
+
"\", exception: "
;
try
{
return
this
.
jsonPath
.
read
(
content
);
}
...
...
@@ -236,7 +236,7 @@ public class JsonPathExpectationsHelper {
private
Object
assertExistsAndReturn
(
String
content
)
throws
ParseException
{
Object
value
=
evaluateJsonPath
(
content
);
String
reason
=
"No value
for
JSON path \""
+
this
.
expression
+
"\""
;
String
reason
=
"No value
at
JSON path \""
+
this
.
expression
+
"\""
;
assertTrue
(
reason
,
value
!=
null
);
return
value
;
}
...
...
spring-test/src/test/java/org/springframework/test/util/JsonPathExpectationsHelperTests.java
浏览文件 @
d2503340
...
...
@@ -64,7 +64,7 @@ public class JsonPathExpectationsHelperTests {
@Test
public
void
assertValueWithDifferentExpectedType
()
throws
Exception
{
exception
.
expect
(
AssertionError
.
class
);
exception
.
expectMessage
(
equalTo
(
"
For
JSON path \"$.nr\", type of value expected:<java.lang.String> but was:<java.lang.Integer>"
));
exception
.
expectMessage
(
equalTo
(
"
At
JSON path \"$.nr\", type of value expected:<java.lang.String> but was:<java.lang.Integer>"
));
new
JsonPathExpectationsHelper
(
"$.nr"
).
assertValue
(
CONTENT
,
"5"
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录