Commit cf41512e authored by Phillip Webb's avatar Phillip Webb

Don't throw checked exceptions from Assert classes

Fixes gh-5709
parent 5881c9c7
......@@ -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));
}
......
......@@ -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);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment