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
Expand all
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
This diff is collapsed.
Click to expand it.
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