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 @@ ...@@ -17,7 +17,6 @@
package org.springframework.boot.test.json; package org.springframework.boot.test.json;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
...@@ -63,9 +62,9 @@ public class BasicJsonTester { ...@@ -63,9 +62,9 @@ public class BasicJsonTester {
* using {@code resourceLoadClass}. * using {@code resourceLoadClass}.
* @param source JSON content or a {@code .json} resource name * @param source JSON content or a {@code .json} resource name
* @return the JSON content * @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)); return getJsonContent(this.loader.getJson(source));
} }
...@@ -74,10 +73,9 @@ public class BasicJsonTester { ...@@ -74,10 +73,9 @@ public class BasicJsonTester {
* @param path the path of the resource to load * @param path the path of the resource to load
* @param resourceLoadClass the classloader used load the resource * @param resourceLoadClass the classloader used load the resource
* @return the JSON content * @return the JSON content
* @throws IOException on load error * @on load error
*/ */
public JsonContent<Object> from(String path, Class<?> resourceLoadClass) public JsonContent<Object> from(String path, Class<?> resourceLoadClass) {
throws IOException {
return getJsonContent(this.loader.getJson(path, resourceLoadClass)); return getJsonContent(this.loader.getJson(path, resourceLoadClass));
} }
...@@ -85,9 +83,9 @@ public class BasicJsonTester { ...@@ -85,9 +83,9 @@ public class BasicJsonTester {
* Create JSON content from the specified JSON bytes. * Create JSON content from the specified JSON bytes.
* @param source the bytes of JSON * @param source the bytes of JSON
* @return the JSON content * @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)); return getJsonContent(this.loader.getJson(source));
} }
...@@ -95,9 +93,9 @@ public class BasicJsonTester { ...@@ -95,9 +93,9 @@ public class BasicJsonTester {
* Create JSON content from the specified JSON file. * Create JSON content from the specified JSON file.
* @param source the file containing JSON * @param source the file containing JSON
* @return the JSON content * @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)); return getJsonContent(this.loader.getJson(source));
} }
...@@ -105,9 +103,9 @@ public class BasicJsonTester { ...@@ -105,9 +103,9 @@ public class BasicJsonTester {
* Create JSON content from the specified JSON input stream. * Create JSON content from the specified JSON input stream.
* @param source the input stream containing JSON * @param source the input stream containing JSON
* @return the JSON content * @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)); return getJsonContent(this.loader.getJson(source));
} }
...@@ -115,9 +113,9 @@ public class BasicJsonTester { ...@@ -115,9 +113,9 @@ public class BasicJsonTester {
* Create JSON content from the specified JSON resource. * Create JSON content from the specified JSON resource.
* @param source the resource containing JSON * @param source the resource containing JSON
* @return the JSON content * @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)); return getJsonContent(this.loader.getJson(source));
} }
......
...@@ -44,7 +44,7 @@ class JsonLoader { ...@@ -44,7 +44,7 @@ class JsonLoader {
return this.resourceLoadClass; return this.resourceLoadClass;
} }
public String getJson(CharSequence source) throws IOException { public String getJson(CharSequence source) {
if (source == null) { if (source == null) {
return null; return null;
} }
...@@ -55,24 +55,39 @@ class JsonLoader { ...@@ -55,24 +55,39 @@ class JsonLoader {
return source.toString(); 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)); return getJson(new ClassPathResource(path, resourceLoadClass));
} }
public String getJson(byte[] source) throws IOException { public String getJson(byte[] source) {
return getJson(new ByteArrayInputStream(source)); return getJson(new ByteArrayInputStream(source));
} }
public String getJson(File source) throws IOException { public String getJson(File source) {
return getJson(new FileInputStream(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 { public String getJson(Resource source) {
return getJson(source.getInputStream()); 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 { public String getJson(InputStream source) {
return FileCopyUtils.copyToString(new InputStreamReader(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