Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
ff8edf8d
Commit
ff8edf8d
authored
Dec 26, 2018
by
Camille Vienot
Committed by
Stephane Nicoll
Dec 31, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use assertJ to generate AssertionError and filter its stacktrace
Closes gh-15569
parent
51936e1a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
12 deletions
+15
-12
JsonContentAssert.java
...org/springframework/boot/test/json/JsonContentAssert.java
+15
-12
No files found.
spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/json/JsonContentAssert.java
View file @
ff8edf8d
...
@@ -45,6 +45,7 @@ import org.springframework.util.StringUtils;
...
@@ -45,6 +45,7 @@ import org.springframework.util.StringUtils;
*
*
* @author Phillip Webb
* @author Phillip Webb
* @author Andy Wilkinson
* @author Andy Wilkinson
* @author Camille Vienot
* @since 1.4.0
* @since 1.4.0
*/
*/
public
class
JsonContentAssert
extends
AbstractAssert
<
JsonContentAssert
,
CharSequence
>
{
public
class
JsonContentAssert
extends
AbstractAssert
<
JsonContentAssert
,
CharSequence
>
{
...
@@ -96,7 +97,8 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
...
@@ -96,7 +97,8 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
if
(
expected
instanceof
Resource
)
{
if
(
expected
instanceof
Resource
)
{
return
isEqualToJson
((
Resource
)
expected
);
return
isEqualToJson
((
Resource
)
expected
);
}
}
throw
new
AssertionError
(
"Unsupport type for JSON assert "
+
expected
.
getClass
());
failWithMessage
(
"Unsupport type for JSON assert {}"
,
expected
.
getClass
());
return
null
;
}
}
/**
/**
...
@@ -432,7 +434,8 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
...
@@ -432,7 +434,8 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
if
(
expected
instanceof
Resource
)
{
if
(
expected
instanceof
Resource
)
{
return
isNotEqualToJson
((
Resource
)
expected
);
return
isNotEqualToJson
((
Resource
)
expected
);
}
}
throw
new
AssertionError
(
"Unsupport type for JSON assert "
+
expected
.
getClass
());
failWithMessage
(
"Unsupport type for JSON assert {]"
,
expected
.
getClass
());
return
null
;
}
}
/**
/**
...
@@ -1031,14 +1034,14 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
...
@@ -1031,14 +1034,14 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
private
JsonContentAssert
assertNotFailed
(
JSONCompareResult
result
)
{
private
JsonContentAssert
assertNotFailed
(
JSONCompareResult
result
)
{
if
(
result
.
failed
())
{
if
(
result
.
failed
())
{
throw
new
AssertionError
(
"JSON Comparison failure: "
+
result
.
getMessage
());
failWithMessage
(
"JSON Comparison failure: {}"
,
result
.
getMessage
());
}
}
return
this
;
return
this
;
}
}
private
JsonContentAssert
assertNotPassed
(
JSONCompareResult
result
)
{
private
JsonContentAssert
assertNotPassed
(
JSONCompareResult
result
)
{
if
(
result
.
passed
())
{
if
(
result
.
passed
())
{
throw
new
AssertionError
(
"JSON Comparison failure: "
+
result
.
getMessage
());
failWithMessage
(
"JSON Comparison failure: {}"
,
result
.
getMessage
());
}
}
return
this
;
return
this
;
}
}
...
@@ -1064,24 +1067,24 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
...
@@ -1064,24 +1067,24 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
if
(
ObjectUtils
.
isEmpty
(
getValue
(
false
))
||
isIndefiniteAndEmpty
())
{
if
(
ObjectUtils
.
isEmpty
(
getValue
(
false
))
||
isIndefiniteAndEmpty
())
{
return
;
return
;
}
}
throw
new
AssertionError
(
getExpectedValueMessage
(
"an empty value"
));
failWithMessage
(
getExpectedValueMessage
(
"an empty value"
));
}
}
public
void
assertDoesNotHaveEmptyValue
()
{
public
void
assertDoesNotHaveEmptyValue
()
{
if
(!
ObjectUtils
.
isEmpty
(
getValue
(
false
)))
{
if
(!
ObjectUtils
.
isEmpty
(
getValue
(
false
)))
{
return
;
return
;
}
}
throw
new
AssertionError
(
getExpectedValueMessage
(
"a non-empty value"
));
failWithMessage
(
getExpectedValueMessage
(
"a non-empty value"
));
}
}
public
void
assertHasValue
(
Class
<?>
type
,
String
expectedDescription
)
{
public
void
assertHasValue
(
Class
<?>
type
,
String
expectedDescription
)
{
Object
value
=
getValue
(
true
);
Object
value
=
getValue
(
true
);
if
(
value
==
null
||
isIndefiniteAndEmpty
())
{
if
(
value
==
null
||
isIndefiniteAndEmpty
())
{
throw
new
AssertionError
(
getNoValueMessage
());
failWithMessage
(
getNoValueMessage
());
}
}
if
(
type
!=
null
&&
!
type
.
isInstance
(
value
))
{
if
(
type
!=
null
&&
!
type
.
isInstance
(
value
))
{
throw
new
AssertionError
(
getExpectedValueMessage
(
expectedDescription
));
failWithMessage
(
getExpectedValueMessage
(
expectedDescription
));
}
}
}
}
...
@@ -1089,7 +1092,7 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
...
@@ -1089,7 +1092,7 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
if
(
getValue
(
false
)
==
null
||
isIndefiniteAndEmpty
())
{
if
(
getValue
(
false
)
==
null
||
isIndefiniteAndEmpty
())
{
return
;
return
;
}
}
throw
new
AssertionError
(
getExpectedValueMessage
(
"no value"
));
failWithMessage
(
getExpectedValueMessage
(
"no value"
));
}
}
private
boolean
isIndefiniteAndEmpty
()
{
private
boolean
isIndefiniteAndEmpty
()
{
...
@@ -1110,10 +1113,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
...
@@ -1110,10 +1113,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
return
this
.
jsonPath
.
read
((
json
!=
null
)
?
json
.
toString
()
:
null
);
return
this
.
jsonPath
.
read
((
json
!=
null
)
?
json
.
toString
()
:
null
);
}
}
catch
(
Exception
ex
)
{
catch
(
Exception
ex
)
{
if
(
!
required
)
{
if
(
required
)
{
return
null
;
failWithMessage
(
"{}. {}"
,
getNoValueMessage
(),
ex
.
getMessage
())
;
}
}
throw
new
AssertionError
(
getNoValueMessage
()
+
". "
+
ex
.
getMessage
())
;
return
null
;
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment