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
cf41512e
Commit
cf41512e
authored
Apr 16, 2016
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't throw checked exceptions from Assert classes
Fixes gh-5709
parent
5881c9c7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
163 additions
and
177 deletions
+163
-177
BasicJsonTester.java
...a/org/springframework/boot/test/json/BasicJsonTester.java
+12
-14
JsonContentAssert.java
...org/springframework/boot/test/json/JsonContentAssert.java
+127
-154
JsonLoader.java
...n/java/org/springframework/boot/test/json/JsonLoader.java
+24
-9
No files found.
spring-boot-test/src/main/java/org/springframework/boot/test/json/BasicJsonTester.java
View file @
cf41512e
...
...
@@ -17,7 +17,6 @@
package
org
.
springframework
.
boot
.
test
.
json
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
org.springframework.core.io.Resource
;
...
...
@@ -63,9 +62,9 @@ public class BasicJsonTester {
* using {@code resourceLoadClass}.
* @param source JSON content or a {@code .json} resource name
* @return the JSON content
* @
throws IOException
on load error
* @on load error
*/
public
JsonContent
<
Object
>
from
(
CharSequence
source
)
throws
IOException
{
public
JsonContent
<
Object
>
from
(
CharSequence
source
)
{
return
getJsonContent
(
this
.
loader
.
getJson
(
source
));
}
...
...
@@ -74,10 +73,9 @@ public class BasicJsonTester {
* @param path the path of the resource to load
* @param resourceLoadClass the classloader used load the resource
* @return the JSON content
* @
throws IOException
on load error
* @on load error
*/
public
JsonContent
<
Object
>
from
(
String
path
,
Class
<?>
resourceLoadClass
)
throws
IOException
{
public
JsonContent
<
Object
>
from
(
String
path
,
Class
<?>
resourceLoadClass
)
{
return
getJsonContent
(
this
.
loader
.
getJson
(
path
,
resourceLoadClass
));
}
...
...
@@ -85,9 +83,9 @@ public class BasicJsonTester {
* Create JSON content from the specified JSON bytes.
* @param source the bytes of JSON
* @return the JSON content
* @
throws IOException
on load error
* @on load error
*/
public
JsonContent
<
Object
>
from
(
byte
[]
source
)
throws
IOException
{
public
JsonContent
<
Object
>
from
(
byte
[]
source
)
{
return
getJsonContent
(
this
.
loader
.
getJson
(
source
));
}
...
...
@@ -95,9 +93,9 @@ public class BasicJsonTester {
* Create JSON content from the specified JSON file.
* @param source the file containing JSON
* @return the JSON content
* @
throws IOException
on load error
* @on load error
*/
public
JsonContent
<
Object
>
from
(
File
source
)
throws
IOException
{
public
JsonContent
<
Object
>
from
(
File
source
)
{
return
getJsonContent
(
this
.
loader
.
getJson
(
source
));
}
...
...
@@ -105,9 +103,9 @@ public class BasicJsonTester {
* Create JSON content from the specified JSON input stream.
* @param source the input stream containing JSON
* @return the JSON content
* @
throws IOException
on load error
* @on load error
*/
public
JsonContent
<
Object
>
from
(
InputStream
source
)
throws
IOException
{
public
JsonContent
<
Object
>
from
(
InputStream
source
)
{
return
getJsonContent
(
this
.
loader
.
getJson
(
source
));
}
...
...
@@ -115,9 +113,9 @@ public class BasicJsonTester {
* Create JSON content from the specified JSON resource.
* @param source the resource containing JSON
* @return the JSON content
* @
throws IOException
on load error
* @on load error
*/
public
JsonContent
<
Object
>
from
(
Resource
source
)
throws
IOException
{
public
JsonContent
<
Object
>
from
(
Resource
source
)
{
return
getJsonContent
(
this
.
loader
.
getJson
(
source
));
}
...
...
spring-boot-test/src/main/java/org/springframework/boot/test/json/JsonContentAssert.java
View file @
cf41512e
...
...
@@ -17,7 +17,6 @@
package
org
.
springframework
.
boot
.
test
.
json
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -67,28 +66,22 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
*/
@Override
public
JsonContentAssert
isEqualTo
(
Object
expected
)
{
try
{
if
(
expected
==
null
||
expected
instanceof
CharSequence
)
{
return
isEqualToJson
((
CharSequence
)
expected
);
}
if
(
expected
instanceof
byte
[])
{
return
isEqualToJson
((
byte
[])
expected
);
}
if
(
expected
instanceof
File
)
{
return
isEqualToJson
((
File
)
expected
);
}
if
(
expected
instanceof
InputStream
)
{
return
isEqualToJson
((
InputStream
)
expected
);
}
if
(
expected
instanceof
Resource
)
{
return
isEqualToJson
((
Resource
)
expected
);
}
throw
new
AssertionError
(
"Unsupport type for JSON assert "
+
expected
.
getClass
());
if
(
expected
==
null
||
expected
instanceof
CharSequence
)
{
return
isEqualToJson
((
CharSequence
)
expected
);
}
catch
(
IOException
ex
)
{
throw
new
IllegalStateException
(
ex
);
if
(
expected
instanceof
byte
[]
)
{
return
isEqualToJson
((
byte
[])
expected
);
}
if
(
expected
instanceof
File
)
{
return
isEqualToJson
((
File
)
expected
);
}
if
(
expected
instanceof
InputStream
)
{
return
isEqualToJson
((
InputStream
)
expected
);
}
if
(
expected
instanceof
Resource
)
{
return
isEqualToJson
((
Resource
)
expected
);
}
throw
new
AssertionError
(
"Unsupport type for JSON assert "
+
expected
.
getClass
());
}
/**
...
...
@@ -99,10 +92,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected the expected JSON or the name of a resource containing the expected
* JSON
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is not equal to the given one
*/
public
JsonContentAssert
isEqualToJson
(
CharSequence
expected
)
throws
IOException
{
public
JsonContentAssert
isEqualToJson
(
CharSequence
expected
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotFailed
(
compare
(
expectedJson
,
JSONCompareMode
.
LENIENT
));
}
...
...
@@ -113,11 +106,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param path the name of a resource containing the expected JSON
* @param resourceLoadClass the source class used to load the resource
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is not equal to the given one
*/
public
JsonContentAssert
isEqualToJson
(
String
path
,
Class
<?>
resourceLoadClass
)
throws
IOException
{
public
JsonContentAssert
isEqualToJson
(
String
path
,
Class
<?>
resourceLoadClass
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
path
,
resourceLoadClass
);
return
assertNotFailed
(
compare
(
expectedJson
,
JSONCompareMode
.
LENIENT
));
}
...
...
@@ -127,10 +119,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* to the specified JSON bytes.
* @param expected the expected JSON bytes
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is not equal to the given one
*/
public
JsonContentAssert
isEqualToJson
(
byte
[]
expected
)
throws
IOException
{
public
JsonContentAssert
isEqualToJson
(
byte
[]
expected
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotFailed
(
compare
(
expectedJson
,
JSONCompareMode
.
LENIENT
));
}
...
...
@@ -140,10 +132,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* to the specified JSON file.
* @param expected a file containing the expected JSON
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is not equal to the given one
*/
public
JsonContentAssert
isEqualToJson
(
File
expected
)
throws
IOException
{
public
JsonContentAssert
isEqualToJson
(
File
expected
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotFailed
(
compare
(
expectedJson
,
JSONCompareMode
.
LENIENT
));
}
...
...
@@ -153,10 +145,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* to the specified JSON input stream.
* @param expected an input stream containing the expected JSON
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is not equal to the given one
*/
public
JsonContentAssert
isEqualToJson
(
InputStream
expected
)
throws
IOException
{
public
JsonContentAssert
isEqualToJson
(
InputStream
expected
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotFailed
(
compare
(
expectedJson
,
JSONCompareMode
.
LENIENT
));
}
...
...
@@ -166,10 +158,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* to the specified JSON resource.
* @param expected a resource containing the expected JSON
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is not equal to the given one
*/
public
JsonContentAssert
isEqualToJson
(
Resource
expected
)
throws
IOException
{
public
JsonContentAssert
isEqualToJson
(
Resource
expected
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotFailed
(
compare
(
expectedJson
,
JSONCompareMode
.
LENIENT
));
}
...
...
@@ -182,11 +174,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected the expected JSON or the name of a resource containing the expected
* JSON
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is not equal to the given one
*/
public
JsonContentAssert
isStrictlyEqualToJson
(
CharSequence
expected
)
throws
IOException
{
public
JsonContentAssert
isStrictlyEqualToJson
(
CharSequence
expected
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotFailed
(
compare
(
expectedJson
,
JSONCompareMode
.
STRICT
));
}
...
...
@@ -197,11 +188,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param path the name of a resource containing the expected JSON
* @param resourceLoadClass the source class used to load the resource
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is not equal to the given one
*/
public
JsonContentAssert
isStrictlyEqualToJson
(
String
path
,
Class
<?>
resourceLoadClass
)
throws
IOException
{
Class
<?>
resourceLoadClass
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
path
,
resourceLoadClass
);
return
assertNotFailed
(
compare
(
expectedJson
,
JSONCompareMode
.
STRICT
));
}
...
...
@@ -211,10 +202,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* the specified JSON bytes.
* @param expected the expected JSON bytes
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is not equal to the given one
*/
public
JsonContentAssert
isStrictlyEqualToJson
(
byte
[]
expected
)
throws
IOException
{
public
JsonContentAssert
isStrictlyEqualToJson
(
byte
[]
expected
)
{
return
assertNotFailed
(
compare
(
this
.
loader
.
getJson
(
expected
),
JSONCompareMode
.
STRICT
));
}
...
...
@@ -224,10 +215,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* the specified JSON file.
* @param expected a file containing the expected JSON
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is not equal to the given one
*/
public
JsonContentAssert
isStrictlyEqualToJson
(
File
expected
)
throws
IOException
{
public
JsonContentAssert
isStrictlyEqualToJson
(
File
expected
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotFailed
(
compare
(
expectedJson
,
JSONCompareMode
.
STRICT
));
}
...
...
@@ -237,11 +228,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* the specified JSON input stream.
* @param expected an input stream containing the expected JSON
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is not equal to the given one
*/
public
JsonContentAssert
isStrictlyEqualToJson
(
InputStream
expected
)
throws
IOException
{
public
JsonContentAssert
isStrictlyEqualToJson
(
InputStream
expected
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotFailed
(
compare
(
expectedJson
,
JSONCompareMode
.
STRICT
));
}
...
...
@@ -251,10 +241,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* the specified JSON resource.
* @param expected a resource containing the expected JSON
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is not equal to the given one
*/
public
JsonContentAssert
isStrictlyEqualToJson
(
Resource
expected
)
throws
IOException
{
public
JsonContentAssert
isStrictlyEqualToJson
(
Resource
expected
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotFailed
(
compare
(
expectedJson
,
JSONCompareMode
.
STRICT
));
}
...
...
@@ -267,11 +257,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* JSON
* @param compareMode the compare mode used when checking
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is not equal to the given one
*/
public
JsonContentAssert
isEqualToJson
(
CharSequence
expected
,
JSONCompareMode
compareMode
)
throws
IOException
{
JSONCompareMode
compareMode
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotFailed
(
compare
(
expectedJson
,
compareMode
));
}
...
...
@@ -282,11 +272,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param resourceLoadClass the source class used to load the resource
* @param compareMode the compare mode used when checking
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is not equal to the given one
*/
public
JsonContentAssert
isEqualToJson
(
String
path
,
Class
<?>
resourceLoadClass
,
JSONCompareMode
compareMode
)
throws
IOException
{
JSONCompareMode
compareMode
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
path
,
resourceLoadClass
);
return
assertNotFailed
(
compare
(
expectedJson
,
compareMode
));
}
...
...
@@ -296,11 +286,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected the expected JSON bytes
* @param compareMode the compare mode used when checking
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is not equal to the given one
*/
public
JsonContentAssert
isEqualToJson
(
byte
[]
expected
,
JSONCompareMode
compareMode
)
throws
IOException
{
public
JsonContentAssert
isEqualToJson
(
byte
[]
expected
,
JSONCompareMode
compareMode
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotFailed
(
compare
(
expectedJson
,
compareMode
));
}
...
...
@@ -310,11 +299,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected a file containing the expected JSON
* @param compareMode the compare mode used when checking
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is not equal to the given one
*/
public
JsonContentAssert
isEqualToJson
(
File
expected
,
JSONCompareMode
compareMode
)
throws
IOException
{
public
JsonContentAssert
isEqualToJson
(
File
expected
,
JSONCompareMode
compareMode
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotFailed
(
compare
(
expectedJson
,
compareMode
));
}
...
...
@@ -324,11 +312,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected an input stream containing the expected JSON
* @param compareMode the compare mode used when checking
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is not equal to the given one
*/
public
JsonContentAssert
isEqualToJson
(
InputStream
expected
,
JSONCompareMode
compareMode
)
throws
IOException
{
JSONCompareMode
compareMode
)
{
return
assertNotFailed
(
compare
(
this
.
loader
.
getJson
(
expected
),
compareMode
));
}
...
...
@@ -337,11 +325,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected a resource containing the expected JSON
* @param compareMode the compare mode used when checking
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is not equal to the given one
*/
public
JsonContentAssert
isEqualToJson
(
Resource
expected
,
JSONCompareMode
compareMode
)
throws
IOException
{
public
JsonContentAssert
isEqualToJson
(
Resource
expected
,
JSONCompareMode
compareMode
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotFailed
(
compare
(
expectedJson
,
compareMode
));
}
...
...
@@ -354,11 +342,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* JSON
* @param comparator the comparator used when checking
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is not equal to the given one
*/
public
JsonContentAssert
isEqualToJson
(
CharSequence
expected
,
JSONComparator
comparator
)
throws
IOException
{
JSONComparator
comparator
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotFailed
(
compare
(
expectedJson
,
comparator
));
}
...
...
@@ -369,11 +357,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param resourceLoadClass the source class used to load the resource
* @param comparator the comparator used when checking
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is not equal to the given one
*/
public
JsonContentAssert
isEqualToJson
(
String
path
,
Class
<?>
resourceLoadClass
,
JSONComparator
comparator
)
throws
IOException
{
JSONComparator
comparator
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
path
,
resourceLoadClass
);
return
assertNotFailed
(
compare
(
expectedJson
,
comparator
));
}
...
...
@@ -383,11 +371,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected the expected JSON bytes
* @param comparator the comparator used when checking
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is not equal to the given one
*/
public
JsonContentAssert
isEqualToJson
(
byte
[]
expected
,
JSONComparator
comparator
)
throws
IOException
{
public
JsonContentAssert
isEqualToJson
(
byte
[]
expected
,
JSONComparator
comparator
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotFailed
(
compare
(
expectedJson
,
comparator
));
}
...
...
@@ -397,11 +384,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected a file containing the expected JSON
* @param comparator the comparator used when checking
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is not equal to the given one
*/
public
JsonContentAssert
isEqualToJson
(
File
expected
,
JSONComparator
comparator
)
throws
IOException
{
public
JsonContentAssert
isEqualToJson
(
File
expected
,
JSONComparator
comparator
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotFailed
(
compare
(
expectedJson
,
comparator
));
}
...
...
@@ -411,11 +397,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected an input stream containing the expected JSON
* @param comparator the comparator used when checking
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is not equal to the given one
*/
public
JsonContentAssert
isEqualToJson
(
InputStream
expected
,
JSONComparator
comparator
)
throws
IOException
{
JSONComparator
comparator
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotFailed
(
compare
(
expectedJson
,
comparator
));
}
...
...
@@ -425,11 +411,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected a resource containing the expected JSON
* @param comparator the comparator used when checking
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is not equal to the given one
*/
public
JsonContentAssert
isEqualToJson
(
Resource
expected
,
JSONComparator
comparator
)
throws
IOException
{
public
JsonContentAssert
isEqualToJson
(
Resource
expected
,
JSONComparator
comparator
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotFailed
(
compare
(
expectedJson
,
comparator
));
}
...
...
@@ -441,28 +426,22 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
*/
@Override
public
JsonContentAssert
isNotEqualTo
(
Object
expected
)
{
try
{
if
(
expected
==
null
||
expected
instanceof
CharSequence
)
{
return
isNotEqualToJson
((
CharSequence
)
expected
);
}
if
(
expected
instanceof
byte
[])
{
return
isNotEqualToJson
((
byte
[])
expected
);
}
if
(
expected
instanceof
File
)
{
return
isNotEqualToJson
((
File
)
expected
);
}
if
(
expected
instanceof
InputStream
)
{
return
isNotEqualToJson
((
InputStream
)
expected
);
}
if
(
expected
instanceof
Resource
)
{
return
isNotEqualToJson
((
Resource
)
expected
);
}
throw
new
AssertionError
(
"Unsupport type for JSON assert "
+
expected
.
getClass
());
if
(
expected
==
null
||
expected
instanceof
CharSequence
)
{
return
isNotEqualToJson
((
CharSequence
)
expected
);
}
if
(
expected
instanceof
byte
[])
{
return
isNotEqualToJson
((
byte
[])
expected
);
}
if
(
expected
instanceof
File
)
{
return
isNotEqualToJson
((
File
)
expected
);
}
if
(
expected
instanceof
InputStream
)
{
return
isNotEqualToJson
((
InputStream
)
expected
);
}
catch
(
IOException
ex
)
{
throw
new
IllegalStateException
(
ex
);
if
(
expected
instanceof
Resource
)
{
return
isNotEqualToJson
((
Resource
)
expected
);
}
throw
new
AssertionError
(
"Unsupport type for JSON assert "
+
expected
.
getClass
());
}
/**
...
...
@@ -473,10 +452,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected the expected JSON or the name of a resource containing the expected
* JSON
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is equal to the given one
*/
public
JsonContentAssert
isNotEqualToJson
(
CharSequence
expected
)
throws
IOException
{
public
JsonContentAssert
isNotEqualToJson
(
CharSequence
expected
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotPassed
(
compare
(
expectedJson
,
JSONCompareMode
.
LENIENT
));
}
...
...
@@ -487,11 +466,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param path the name of a resource containing the expected JSON
* @param resourceLoadClass the source class used to load the resource
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is equal to the given one
*/
public
JsonContentAssert
isNotEqualToJson
(
String
path
,
Class
<?>
resourceLoadClass
)
throws
IOException
{
public
JsonContentAssert
isNotEqualToJson
(
String
path
,
Class
<?>
resourceLoadClass
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
path
,
resourceLoadClass
);
return
assertNotPassed
(
compare
(
expectedJson
,
JSONCompareMode
.
LENIENT
));
}
...
...
@@ -501,10 +479,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* equal to the specified JSON bytes.
* @param expected the expected JSON bytes
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is equal to the given one
*/
public
JsonContentAssert
isNotEqualToJson
(
byte
[]
expected
)
throws
IOException
{
public
JsonContentAssert
isNotEqualToJson
(
byte
[]
expected
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotPassed
(
compare
(
expectedJson
,
JSONCompareMode
.
LENIENT
));
}
...
...
@@ -514,10 +492,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* equal to the specified JSON file.
* @param expected a file containing the expected JSON
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is equal to the given one
*/
public
JsonContentAssert
isNotEqualToJson
(
File
expected
)
throws
IOException
{
public
JsonContentAssert
isNotEqualToJson
(
File
expected
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotPassed
(
compare
(
expectedJson
,
JSONCompareMode
.
LENIENT
));
}
...
...
@@ -527,10 +505,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* equal to the specified JSON input stream.
* @param expected an input stream containing the expected JSON
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is equal to the given one
*/
public
JsonContentAssert
isNotEqualToJson
(
InputStream
expected
)
throws
IOException
{
public
JsonContentAssert
isNotEqualToJson
(
InputStream
expected
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotPassed
(
compare
(
expectedJson
,
JSONCompareMode
.
LENIENT
));
}
...
...
@@ -540,10 +518,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* equal to the specified JSON resource.
* @param expected a resource containing the expected JSON
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is equal to the given one
*/
public
JsonContentAssert
isNotEqualToJson
(
Resource
expected
)
throws
IOException
{
public
JsonContentAssert
isNotEqualToJson
(
Resource
expected
)
{
return
assertNotPassed
(
compare
(
this
.
loader
.
getJson
(
expected
),
JSONCompareMode
.
LENIENT
));
}
...
...
@@ -556,11 +534,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected the expected JSON or the name of a resource containing the expected
* JSON
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is equal to the given one
*/
public
JsonContentAssert
isNotStrictlyEqualToJson
(
CharSequence
expected
)
throws
IOException
{
public
JsonContentAssert
isNotStrictlyEqualToJson
(
CharSequence
expected
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotPassed
(
compare
(
expectedJson
,
JSONCompareMode
.
STRICT
));
}
...
...
@@ -571,11 +548,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param path the name of a resource containing the expected JSON
* @param resourceLoadClass the source class used to load the resource
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is equal to the given one
*/
public
JsonContentAssert
isNotStrictlyEqualToJson
(
String
path
,
Class
<?>
resourceLoadClass
)
throws
IOException
{
Class
<?>
resourceLoadClass
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
path
,
resourceLoadClass
);
return
assertNotPassed
(
compare
(
expectedJson
,
JSONCompareMode
.
STRICT
));
}
...
...
@@ -585,11 +562,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* to the specified JSON bytes.
* @param expected the expected JSON bytes
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is equal to the given one
*/
public
JsonContentAssert
isNotStrictlyEqualToJson
(
byte
[]
expected
)
throws
IOException
{
public
JsonContentAssert
isNotStrictlyEqualToJson
(
byte
[]
expected
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotPassed
(
compare
(
expectedJson
,
JSONCompareMode
.
STRICT
));
}
...
...
@@ -599,10 +575,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* to the specified JSON file.
* @param expected a file containing the expected JSON
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is equal to the given one
*/
public
JsonContentAssert
isNotStrictlyEqualToJson
(
File
expected
)
throws
IOException
{
public
JsonContentAssert
isNotStrictlyEqualToJson
(
File
expected
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotPassed
(
compare
(
expectedJson
,
JSONCompareMode
.
STRICT
));
}
...
...
@@ -612,11 +588,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* to the specified JSON input stream.
* @param expected an input stream containing the expected JSON
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is equal to the given one
*/
public
JsonContentAssert
isNotStrictlyEqualToJson
(
InputStream
expected
)
throws
IOException
{
public
JsonContentAssert
isNotStrictlyEqualToJson
(
InputStream
expected
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotPassed
(
compare
(
expectedJson
,
JSONCompareMode
.
STRICT
));
}
...
...
@@ -626,11 +601,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* to the specified JSON resource.
* @param expected a resource containing the expected JSON
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is equal to the given one
*/
public
JsonContentAssert
isNotStrictlyEqualToJson
(
Resource
expected
)
throws
IOException
{
public
JsonContentAssert
isNotStrictlyEqualToJson
(
Resource
expected
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotPassed
(
compare
(
expectedJson
,
JSONCompareMode
.
STRICT
));
}
...
...
@@ -643,11 +617,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* JSON
* @param compareMode the compare mode used when checking
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is equal to the given one
*/
public
JsonContentAssert
isNotEqualToJson
(
CharSequence
expected
,
JSONCompareMode
compareMode
)
throws
IOException
{
JSONCompareMode
compareMode
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotPassed
(
compare
(
expectedJson
,
compareMode
));
}
...
...
@@ -658,11 +632,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param resourceLoadClass the source class used to load the resource
* @param compareMode the compare mode used when checking
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is equal to the given one
*/
public
JsonContentAssert
isNotEqualToJson
(
String
path
,
Class
<?>
resourceLoadClass
,
JSONCompareMode
compareMode
)
throws
IOException
{
JSONCompareMode
compareMode
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
path
,
resourceLoadClass
);
return
assertNotPassed
(
compare
(
expectedJson
,
compareMode
));
}
...
...
@@ -672,11 +646,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected the expected JSON bytes
* @param compareMode the compare mode used when checking
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is equal to the given one
*/
public
JsonContentAssert
isNotEqualToJson
(
byte
[]
expected
,
JSONCompareMode
compareMode
)
throws
IOException
{
JSONCompareMode
compareMode
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotPassed
(
compare
(
expectedJson
,
compareMode
));
}
...
...
@@ -686,11 +660,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected a file containing the expected JSON
* @param compareMode the compare mode used when checking
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is equal to the given one
*/
public
JsonContentAssert
isNotEqualToJson
(
File
expected
,
JSONCompareMode
compareMode
)
throws
IOException
{
public
JsonContentAssert
isNotEqualToJson
(
File
expected
,
JSONCompareMode
compareMode
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotPassed
(
compare
(
expectedJson
,
compareMode
));
}
...
...
@@ -700,11 +674,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected an input stream containing the expected JSON
* @param compareMode the compare mode used when checking
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is equal to the given one
*/
public
JsonContentAssert
isNotEqualToJson
(
InputStream
expected
,
JSONCompareMode
compareMode
)
throws
IOException
{
JSONCompareMode
compareMode
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotPassed
(
compare
(
expectedJson
,
compareMode
));
}
...
...
@@ -714,11 +688,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected a resource containing the expected JSON
* @param compareMode the compare mode used when checking
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is equal to the given one
*/
public
JsonContentAssert
isNotEqualToJson
(
Resource
expected
,
JSONCompareMode
compareMode
)
throws
IOException
{
JSONCompareMode
compareMode
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotPassed
(
compare
(
expectedJson
,
compareMode
));
}
...
...
@@ -731,11 +705,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* JSON
* @param comparator the comparator used when checking
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is equal to the given one
*/
public
JsonContentAssert
isNotEqualToJson
(
CharSequence
expected
,
JSONComparator
comparator
)
throws
IOException
{
JSONComparator
comparator
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotPassed
(
compare
(
expectedJson
,
comparator
));
}
...
...
@@ -746,11 +720,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param resourceLoadClass the source class used to load the resource
* @param comparator the comparator used when checking
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is equal to the given one
*/
public
JsonContentAssert
isNotEqualToJson
(
String
path
,
Class
<?>
resourceLoadClass
,
JSONComparator
comparator
)
throws
IOException
{
JSONComparator
comparator
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
path
,
resourceLoadClass
);
return
assertNotPassed
(
compare
(
expectedJson
,
comparator
));
}
...
...
@@ -760,11 +734,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected the expected JSON bytes
* @param comparator the comparator used when checking
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is equal to the given one
*/
public
JsonContentAssert
isNotEqualToJson
(
byte
[]
expected
,
JSONComparator
comparator
)
throws
IOException
{
public
JsonContentAssert
isNotEqualToJson
(
byte
[]
expected
,
JSONComparator
comparator
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotPassed
(
compare
(
expectedJson
,
comparator
));
}
...
...
@@ -774,11 +748,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected a file containing the expected JSON
* @param comparator the comparator used when checking
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is equal to the given one
*/
public
JsonContentAssert
isNotEqualToJson
(
File
expected
,
JSONComparator
comparator
)
throws
IOException
{
public
JsonContentAssert
isNotEqualToJson
(
File
expected
,
JSONComparator
comparator
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotPassed
(
compare
(
expectedJson
,
comparator
));
}
...
...
@@ -788,11 +761,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected an input stream containing the expected JSON
* @param comparator the comparator used when checking
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is equal to the given one
*/
public
JsonContentAssert
isNotEqualToJson
(
InputStream
expected
,
JSONComparator
comparator
)
throws
IOException
{
JSONComparator
comparator
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotPassed
(
compare
(
expectedJson
,
comparator
));
}
...
...
@@ -802,11 +775,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected a resource containing the expected JSON
* @param comparator the comparator used when checking
* @return {@code this} assertion object
* @
throws IOException
on IO error
* @on IO error
* @throws AssertionError if the actual JSON value is equal to the given one
*/
public
JsonContentAssert
isNotEqualToJson
(
Resource
expected
,
JSONComparator
comparator
)
throws
IOException
{
JSONComparator
comparator
)
{
String
expectedJson
=
this
.
loader
.
getJson
(
expected
);
return
assertNotPassed
(
compare
(
expectedJson
,
comparator
));
}
...
...
spring-boot-test/src/main/java/org/springframework/boot/test/json/JsonLoader.java
View file @
cf41512e
...
...
@@ -44,7 +44,7 @@ class JsonLoader {
return
this
.
resourceLoadClass
;
}
public
String
getJson
(
CharSequence
source
)
throws
IOException
{
public
String
getJson
(
CharSequence
source
)
{
if
(
source
==
null
)
{
return
null
;
}
...
...
@@ -55,24 +55,39 @@ class JsonLoader {
return
source
.
toString
();
}
public
String
getJson
(
String
path
,
Class
<?>
resourceLoadClass
)
throws
IOException
{
public
String
getJson
(
String
path
,
Class
<?>
resourceLoadClass
)
{
return
getJson
(
new
ClassPathResource
(
path
,
resourceLoadClass
));
}
public
String
getJson
(
byte
[]
source
)
throws
IOException
{
public
String
getJson
(
byte
[]
source
)
{
return
getJson
(
new
ByteArrayInputStream
(
source
));
}
public
String
getJson
(
File
source
)
throws
IOException
{
return
getJson
(
new
FileInputStream
(
source
));
public
String
getJson
(
File
source
)
{
try
{
return
getJson
(
new
FileInputStream
(
source
));
}
catch
(
IOException
ex
)
{
throw
new
IllegalStateException
(
"Unable to load JSON from "
+
source
,
ex
);
}
}
public
String
getJson
(
Resource
source
)
throws
IOException
{
return
getJson
(
source
.
getInputStream
());
public
String
getJson
(
Resource
source
)
{
try
{
return
getJson
(
source
.
getInputStream
());
}
catch
(
IOException
ex
)
{
throw
new
IllegalStateException
(
"Unable to load JSON from "
+
source
,
ex
);
}
}
public
String
getJson
(
InputStream
source
)
throws
IOException
{
return
FileCopyUtils
.
copyToString
(
new
InputStreamReader
(
source
));
public
String
getJson
(
InputStream
source
)
{
try
{
return
FileCopyUtils
.
copyToString
(
new
InputStreamReader
(
source
));
}
catch
(
IOException
ex
)
{
throw
new
IllegalStateException
(
"Unable to load JSON from InputStream"
,
ex
);
}
}
}
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