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));
} }
......
...@@ -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 java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -67,28 +66,22 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -67,28 +66,22 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
*/ */
@Override @Override
public JsonContentAssert isEqualTo(Object expected) { public JsonContentAssert isEqualTo(Object expected) {
try { if (expected == null || expected instanceof CharSequence) {
if (expected == null || expected instanceof CharSequence) { return isEqualToJson((CharSequence) expected);
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());
} }
catch (IOException ex) { if (expected instanceof byte[]) {
throw new IllegalStateException(ex); 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 ...@@ -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 * @param expected the expected JSON or the name of a resource containing the expected
* JSON * JSON
* @return {@code this} assertion object * @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 * @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); String expectedJson = this.loader.getJson(expected);
return assertNotFailed(compare(expectedJson, JSONCompareMode.LENIENT)); return assertNotFailed(compare(expectedJson, JSONCompareMode.LENIENT));
} }
...@@ -113,11 +106,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -113,11 +106,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param path the name of a resource containing the expected JSON * @param path the name of a resource containing the expected JSON
* @param resourceLoadClass the source class used to load the resource * @param resourceLoadClass the source class used to load the resource
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is not equal to the given one
*/ */
public JsonContentAssert isEqualToJson(String path, Class<?> resourceLoadClass) public JsonContentAssert isEqualToJson(String path, Class<?> resourceLoadClass) {
throws IOException {
String expectedJson = this.loader.getJson(path, resourceLoadClass); String expectedJson = this.loader.getJson(path, resourceLoadClass);
return assertNotFailed(compare(expectedJson, JSONCompareMode.LENIENT)); return assertNotFailed(compare(expectedJson, JSONCompareMode.LENIENT));
} }
...@@ -127,10 +119,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -127,10 +119,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* to the specified JSON bytes. * to the specified JSON bytes.
* @param expected the expected JSON bytes * @param expected the expected JSON bytes
* @return {@code this} assertion object * @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 * @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); String expectedJson = this.loader.getJson(expected);
return assertNotFailed(compare(expectedJson, JSONCompareMode.LENIENT)); return assertNotFailed(compare(expectedJson, JSONCompareMode.LENIENT));
} }
...@@ -140,10 +132,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -140,10 +132,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* to the specified JSON file. * to the specified JSON file.
* @param expected a file containing the expected JSON * @param expected a file containing the expected JSON
* @return {@code this} assertion object * @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 * @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); String expectedJson = this.loader.getJson(expected);
return assertNotFailed(compare(expectedJson, JSONCompareMode.LENIENT)); return assertNotFailed(compare(expectedJson, JSONCompareMode.LENIENT));
} }
...@@ -153,10 +145,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -153,10 +145,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* to the specified JSON input stream. * to the specified JSON input stream.
* @param expected an input stream containing the expected JSON * @param expected an input stream containing the expected JSON
* @return {@code this} assertion object * @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 * @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); String expectedJson = this.loader.getJson(expected);
return assertNotFailed(compare(expectedJson, JSONCompareMode.LENIENT)); return assertNotFailed(compare(expectedJson, JSONCompareMode.LENIENT));
} }
...@@ -166,10 +158,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -166,10 +158,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* to the specified JSON resource. * to the specified JSON resource.
* @param expected a resource containing the expected JSON * @param expected a resource containing the expected JSON
* @return {@code this} assertion object * @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 * @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); String expectedJson = this.loader.getJson(expected);
return assertNotFailed(compare(expectedJson, JSONCompareMode.LENIENT)); return assertNotFailed(compare(expectedJson, JSONCompareMode.LENIENT));
} }
...@@ -182,11 +174,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -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 * @param expected the expected JSON or the name of a resource containing the expected
* JSON * JSON
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is not equal to the given one
*/ */
public JsonContentAssert isStrictlyEqualToJson(CharSequence expected) public JsonContentAssert isStrictlyEqualToJson(CharSequence expected) {
throws IOException {
String expectedJson = this.loader.getJson(expected); String expectedJson = this.loader.getJson(expected);
return assertNotFailed(compare(expectedJson, JSONCompareMode.STRICT)); return assertNotFailed(compare(expectedJson, JSONCompareMode.STRICT));
} }
...@@ -197,11 +188,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -197,11 +188,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param path the name of a resource containing the expected JSON * @param path the name of a resource containing the expected JSON
* @param resourceLoadClass the source class used to load the resource * @param resourceLoadClass the source class used to load the resource
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is not equal to the given one
*/ */
public JsonContentAssert isStrictlyEqualToJson(String path, public JsonContentAssert isStrictlyEqualToJson(String path,
Class<?> resourceLoadClass) throws IOException { Class<?> resourceLoadClass) {
String expectedJson = this.loader.getJson(path, resourceLoadClass); String expectedJson = this.loader.getJson(path, resourceLoadClass);
return assertNotFailed(compare(expectedJson, JSONCompareMode.STRICT)); return assertNotFailed(compare(expectedJson, JSONCompareMode.STRICT));
} }
...@@ -211,10 +202,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -211,10 +202,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* the specified JSON bytes. * the specified JSON bytes.
* @param expected the expected JSON bytes * @param expected the expected JSON bytes
* @return {@code this} assertion object * @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 * @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( return assertNotFailed(
compare(this.loader.getJson(expected), JSONCompareMode.STRICT)); compare(this.loader.getJson(expected), JSONCompareMode.STRICT));
} }
...@@ -224,10 +215,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -224,10 +215,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* the specified JSON file. * the specified JSON file.
* @param expected a file containing the expected JSON * @param expected a file containing the expected JSON
* @return {@code this} assertion object * @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 * @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); String expectedJson = this.loader.getJson(expected);
return assertNotFailed(compare(expectedJson, JSONCompareMode.STRICT)); return assertNotFailed(compare(expectedJson, JSONCompareMode.STRICT));
} }
...@@ -237,11 +228,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -237,11 +228,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* the specified JSON input stream. * the specified JSON input stream.
* @param expected an input stream containing the expected JSON * @param expected an input stream containing the expected JSON
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is not equal to the given one
*/ */
public JsonContentAssert isStrictlyEqualToJson(InputStream expected) public JsonContentAssert isStrictlyEqualToJson(InputStream expected) {
throws IOException {
String expectedJson = this.loader.getJson(expected); String expectedJson = this.loader.getJson(expected);
return assertNotFailed(compare(expectedJson, JSONCompareMode.STRICT)); return assertNotFailed(compare(expectedJson, JSONCompareMode.STRICT));
} }
...@@ -251,10 +241,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -251,10 +241,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* the specified JSON resource. * the specified JSON resource.
* @param expected a resource containing the expected JSON * @param expected a resource containing the expected JSON
* @return {@code this} assertion object * @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 * @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); String expectedJson = this.loader.getJson(expected);
return assertNotFailed(compare(expectedJson, JSONCompareMode.STRICT)); return assertNotFailed(compare(expectedJson, JSONCompareMode.STRICT));
} }
...@@ -267,11 +257,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -267,11 +257,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* JSON * JSON
* @param compareMode the compare mode used when checking * @param compareMode the compare mode used when checking
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is not equal to the given one
*/ */
public JsonContentAssert isEqualToJson(CharSequence expected, public JsonContentAssert isEqualToJson(CharSequence expected,
JSONCompareMode compareMode) throws IOException { JSONCompareMode compareMode) {
String expectedJson = this.loader.getJson(expected); String expectedJson = this.loader.getJson(expected);
return assertNotFailed(compare(expectedJson, compareMode)); return assertNotFailed(compare(expectedJson, compareMode));
} }
...@@ -282,11 +272,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -282,11 +272,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param resourceLoadClass the source class used to load the resource * @param resourceLoadClass the source class used to load the resource
* @param compareMode the compare mode used when checking * @param compareMode the compare mode used when checking
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is not equal to the given one
*/ */
public JsonContentAssert isEqualToJson(String path, Class<?> resourceLoadClass, public JsonContentAssert isEqualToJson(String path, Class<?> resourceLoadClass,
JSONCompareMode compareMode) throws IOException { JSONCompareMode compareMode) {
String expectedJson = this.loader.getJson(path, resourceLoadClass); String expectedJson = this.loader.getJson(path, resourceLoadClass);
return assertNotFailed(compare(expectedJson, compareMode)); return assertNotFailed(compare(expectedJson, compareMode));
} }
...@@ -296,11 +286,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -296,11 +286,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected the expected JSON bytes * @param expected the expected JSON bytes
* @param compareMode the compare mode used when checking * @param compareMode the compare mode used when checking
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is not equal to the given one
*/ */
public JsonContentAssert isEqualToJson(byte[] expected, JSONCompareMode compareMode) public JsonContentAssert isEqualToJson(byte[] expected, JSONCompareMode compareMode) {
throws IOException {
String expectedJson = this.loader.getJson(expected); String expectedJson = this.loader.getJson(expected);
return assertNotFailed(compare(expectedJson, compareMode)); return assertNotFailed(compare(expectedJson, compareMode));
} }
...@@ -310,11 +299,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -310,11 +299,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected a file containing the expected JSON * @param expected a file containing the expected JSON
* @param compareMode the compare mode used when checking * @param compareMode the compare mode used when checking
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is not equal to the given one
*/ */
public JsonContentAssert isEqualToJson(File expected, JSONCompareMode compareMode) public JsonContentAssert isEqualToJson(File expected, JSONCompareMode compareMode) {
throws IOException {
String expectedJson = this.loader.getJson(expected); String expectedJson = this.loader.getJson(expected);
return assertNotFailed(compare(expectedJson, compareMode)); return assertNotFailed(compare(expectedJson, compareMode));
} }
...@@ -324,11 +312,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -324,11 +312,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected an input stream containing the expected JSON * @param expected an input stream containing the expected JSON
* @param compareMode the compare mode used when checking * @param compareMode the compare mode used when checking
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is not equal to the given one
*/ */
public JsonContentAssert isEqualToJson(InputStream expected, public JsonContentAssert isEqualToJson(InputStream expected,
JSONCompareMode compareMode) throws IOException { JSONCompareMode compareMode) {
return assertNotFailed(compare(this.loader.getJson(expected), compareMode)); return assertNotFailed(compare(this.loader.getJson(expected), compareMode));
} }
...@@ -337,11 +325,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -337,11 +325,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected a resource containing the expected JSON * @param expected a resource containing the expected JSON
* @param compareMode the compare mode used when checking * @param compareMode the compare mode used when checking
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is not equal to the given one
*/ */
public JsonContentAssert isEqualToJson(Resource expected, JSONCompareMode compareMode) public JsonContentAssert isEqualToJson(Resource expected,
throws IOException { JSONCompareMode compareMode) {
String expectedJson = this.loader.getJson(expected); String expectedJson = this.loader.getJson(expected);
return assertNotFailed(compare(expectedJson, compareMode)); return assertNotFailed(compare(expectedJson, compareMode));
} }
...@@ -354,11 +342,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -354,11 +342,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* JSON * JSON
* @param comparator the comparator used when checking * @param comparator the comparator used when checking
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is not equal to the given one
*/ */
public JsonContentAssert isEqualToJson(CharSequence expected, public JsonContentAssert isEqualToJson(CharSequence expected,
JSONComparator comparator) throws IOException { JSONComparator comparator) {
String expectedJson = this.loader.getJson(expected); String expectedJson = this.loader.getJson(expected);
return assertNotFailed(compare(expectedJson, comparator)); return assertNotFailed(compare(expectedJson, comparator));
} }
...@@ -369,11 +357,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -369,11 +357,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param resourceLoadClass the source class used to load the resource * @param resourceLoadClass the source class used to load the resource
* @param comparator the comparator used when checking * @param comparator the comparator used when checking
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is not equal to the given one
*/ */
public JsonContentAssert isEqualToJson(String path, Class<?> resourceLoadClass, public JsonContentAssert isEqualToJson(String path, Class<?> resourceLoadClass,
JSONComparator comparator) throws IOException { JSONComparator comparator) {
String expectedJson = this.loader.getJson(path, resourceLoadClass); String expectedJson = this.loader.getJson(path, resourceLoadClass);
return assertNotFailed(compare(expectedJson, comparator)); return assertNotFailed(compare(expectedJson, comparator));
} }
...@@ -383,11 +371,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -383,11 +371,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected the expected JSON bytes * @param expected the expected JSON bytes
* @param comparator the comparator used when checking * @param comparator the comparator used when checking
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is not equal to the given one
*/ */
public JsonContentAssert isEqualToJson(byte[] expected, JSONComparator comparator) public JsonContentAssert isEqualToJson(byte[] expected, JSONComparator comparator) {
throws IOException {
String expectedJson = this.loader.getJson(expected); String expectedJson = this.loader.getJson(expected);
return assertNotFailed(compare(expectedJson, comparator)); return assertNotFailed(compare(expectedJson, comparator));
} }
...@@ -397,11 +384,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -397,11 +384,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected a file containing the expected JSON * @param expected a file containing the expected JSON
* @param comparator the comparator used when checking * @param comparator the comparator used when checking
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is not equal to the given one
*/ */
public JsonContentAssert isEqualToJson(File expected, JSONComparator comparator) public JsonContentAssert isEqualToJson(File expected, JSONComparator comparator) {
throws IOException {
String expectedJson = this.loader.getJson(expected); String expectedJson = this.loader.getJson(expected);
return assertNotFailed(compare(expectedJson, comparator)); return assertNotFailed(compare(expectedJson, comparator));
} }
...@@ -411,11 +397,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -411,11 +397,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected an input stream containing the expected JSON * @param expected an input stream containing the expected JSON
* @param comparator the comparator used when checking * @param comparator the comparator used when checking
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is not equal to the given one
*/ */
public JsonContentAssert isEqualToJson(InputStream expected, public JsonContentAssert isEqualToJson(InputStream expected,
JSONComparator comparator) throws IOException { JSONComparator comparator) {
String expectedJson = this.loader.getJson(expected); String expectedJson = this.loader.getJson(expected);
return assertNotFailed(compare(expectedJson, comparator)); return assertNotFailed(compare(expectedJson, comparator));
} }
...@@ -425,11 +411,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -425,11 +411,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected a resource containing the expected JSON * @param expected a resource containing the expected JSON
* @param comparator the comparator used when checking * @param comparator the comparator used when checking
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is not equal to the given one
*/ */
public JsonContentAssert isEqualToJson(Resource expected, JSONComparator comparator) public JsonContentAssert isEqualToJson(Resource expected, JSONComparator comparator) {
throws IOException {
String expectedJson = this.loader.getJson(expected); String expectedJson = this.loader.getJson(expected);
return assertNotFailed(compare(expectedJson, comparator)); return assertNotFailed(compare(expectedJson, comparator));
} }
...@@ -441,28 +426,22 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -441,28 +426,22 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
*/ */
@Override @Override
public JsonContentAssert isNotEqualTo(Object expected) { public JsonContentAssert isNotEqualTo(Object expected) {
try { if (expected == null || expected instanceof CharSequence) {
if (expected == null || expected instanceof CharSequence) { return isNotEqualToJson((CharSequence) expected);
return isNotEqualToJson((CharSequence) expected); }
} if (expected instanceof byte[]) {
if (expected instanceof byte[]) { return isNotEqualToJson((byte[]) expected);
return isNotEqualToJson((byte[]) expected); }
} if (expected instanceof File) {
if (expected instanceof File) { return isNotEqualToJson((File) expected);
return isNotEqualToJson((File) expected); }
} if (expected instanceof InputStream) {
if (expected instanceof InputStream) { return isNotEqualToJson((InputStream) expected);
return isNotEqualToJson((InputStream) expected);
}
if (expected instanceof Resource) {
return isNotEqualToJson((Resource) expected);
}
throw new AssertionError(
"Unsupport type for JSON assert " + expected.getClass());
} }
catch (IOException ex) { if (expected instanceof Resource) {
throw new IllegalStateException(ex); 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 ...@@ -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 * @param expected the expected JSON or the name of a resource containing the expected
* JSON * JSON
* @return {@code this} assertion object * @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 * @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); String expectedJson = this.loader.getJson(expected);
return assertNotPassed(compare(expectedJson, JSONCompareMode.LENIENT)); return assertNotPassed(compare(expectedJson, JSONCompareMode.LENIENT));
} }
...@@ -487,11 +466,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -487,11 +466,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param path the name of a resource containing the expected JSON * @param path the name of a resource containing the expected JSON
* @param resourceLoadClass the source class used to load the resource * @param resourceLoadClass the source class used to load the resource
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is equal to the given one
*/ */
public JsonContentAssert isNotEqualToJson(String path, Class<?> resourceLoadClass) public JsonContentAssert isNotEqualToJson(String path, Class<?> resourceLoadClass) {
throws IOException {
String expectedJson = this.loader.getJson(path, resourceLoadClass); String expectedJson = this.loader.getJson(path, resourceLoadClass);
return assertNotPassed(compare(expectedJson, JSONCompareMode.LENIENT)); return assertNotPassed(compare(expectedJson, JSONCompareMode.LENIENT));
} }
...@@ -501,10 +479,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -501,10 +479,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* equal to the specified JSON bytes. * equal to the specified JSON bytes.
* @param expected the expected JSON bytes * @param expected the expected JSON bytes
* @return {@code this} assertion object * @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 * @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); String expectedJson = this.loader.getJson(expected);
return assertNotPassed(compare(expectedJson, JSONCompareMode.LENIENT)); return assertNotPassed(compare(expectedJson, JSONCompareMode.LENIENT));
} }
...@@ -514,10 +492,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -514,10 +492,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* equal to the specified JSON file. * equal to the specified JSON file.
* @param expected a file containing the expected JSON * @param expected a file containing the expected JSON
* @return {@code this} assertion object * @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 * @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); String expectedJson = this.loader.getJson(expected);
return assertNotPassed(compare(expectedJson, JSONCompareMode.LENIENT)); return assertNotPassed(compare(expectedJson, JSONCompareMode.LENIENT));
} }
...@@ -527,10 +505,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -527,10 +505,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* equal to the specified JSON input stream. * equal to the specified JSON input stream.
* @param expected an input stream containing the expected JSON * @param expected an input stream containing the expected JSON
* @return {@code this} assertion object * @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 * @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); String expectedJson = this.loader.getJson(expected);
return assertNotPassed(compare(expectedJson, JSONCompareMode.LENIENT)); return assertNotPassed(compare(expectedJson, JSONCompareMode.LENIENT));
} }
...@@ -540,10 +518,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -540,10 +518,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* equal to the specified JSON resource. * equal to the specified JSON resource.
* @param expected a resource containing the expected JSON * @param expected a resource containing the expected JSON
* @return {@code this} assertion object * @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 * @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( return assertNotPassed(
compare(this.loader.getJson(expected), JSONCompareMode.LENIENT)); compare(this.loader.getJson(expected), JSONCompareMode.LENIENT));
} }
...@@ -556,11 +534,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -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 * @param expected the expected JSON or the name of a resource containing the expected
* JSON * JSON
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is equal to the given one
*/ */
public JsonContentAssert isNotStrictlyEqualToJson(CharSequence expected) public JsonContentAssert isNotStrictlyEqualToJson(CharSequence expected) {
throws IOException {
String expectedJson = this.loader.getJson(expected); String expectedJson = this.loader.getJson(expected);
return assertNotPassed(compare(expectedJson, JSONCompareMode.STRICT)); return assertNotPassed(compare(expectedJson, JSONCompareMode.STRICT));
} }
...@@ -571,11 +548,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -571,11 +548,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param path the name of a resource containing the expected JSON * @param path the name of a resource containing the expected JSON
* @param resourceLoadClass the source class used to load the resource * @param resourceLoadClass the source class used to load the resource
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is equal to the given one
*/ */
public JsonContentAssert isNotStrictlyEqualToJson(String path, public JsonContentAssert isNotStrictlyEqualToJson(String path,
Class<?> resourceLoadClass) throws IOException { Class<?> resourceLoadClass) {
String expectedJson = this.loader.getJson(path, resourceLoadClass); String expectedJson = this.loader.getJson(path, resourceLoadClass);
return assertNotPassed(compare(expectedJson, JSONCompareMode.STRICT)); return assertNotPassed(compare(expectedJson, JSONCompareMode.STRICT));
} }
...@@ -585,11 +562,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -585,11 +562,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* to the specified JSON bytes. * to the specified JSON bytes.
* @param expected the expected JSON bytes * @param expected the expected JSON bytes
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is equal to the given one
*/ */
public JsonContentAssert isNotStrictlyEqualToJson(byte[] expected) public JsonContentAssert isNotStrictlyEqualToJson(byte[] expected) {
throws IOException {
String expectedJson = this.loader.getJson(expected); String expectedJson = this.loader.getJson(expected);
return assertNotPassed(compare(expectedJson, JSONCompareMode.STRICT)); return assertNotPassed(compare(expectedJson, JSONCompareMode.STRICT));
} }
...@@ -599,10 +575,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -599,10 +575,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* to the specified JSON file. * to the specified JSON file.
* @param expected a file containing the expected JSON * @param expected a file containing the expected JSON
* @return {@code this} assertion object * @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 * @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); String expectedJson = this.loader.getJson(expected);
return assertNotPassed(compare(expectedJson, JSONCompareMode.STRICT)); return assertNotPassed(compare(expectedJson, JSONCompareMode.STRICT));
} }
...@@ -612,11 +588,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -612,11 +588,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* to the specified JSON input stream. * to the specified JSON input stream.
* @param expected an input stream containing the expected JSON * @param expected an input stream containing the expected JSON
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is equal to the given one
*/ */
public JsonContentAssert isNotStrictlyEqualToJson(InputStream expected) public JsonContentAssert isNotStrictlyEqualToJson(InputStream expected) {
throws IOException {
String expectedJson = this.loader.getJson(expected); String expectedJson = this.loader.getJson(expected);
return assertNotPassed(compare(expectedJson, JSONCompareMode.STRICT)); return assertNotPassed(compare(expectedJson, JSONCompareMode.STRICT));
} }
...@@ -626,11 +601,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -626,11 +601,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* to the specified JSON resource. * to the specified JSON resource.
* @param expected a resource containing the expected JSON * @param expected a resource containing the expected JSON
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is equal to the given one
*/ */
public JsonContentAssert isNotStrictlyEqualToJson(Resource expected) public JsonContentAssert isNotStrictlyEqualToJson(Resource expected) {
throws IOException {
String expectedJson = this.loader.getJson(expected); String expectedJson = this.loader.getJson(expected);
return assertNotPassed(compare(expectedJson, JSONCompareMode.STRICT)); return assertNotPassed(compare(expectedJson, JSONCompareMode.STRICT));
} }
...@@ -643,11 +617,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -643,11 +617,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* JSON * JSON
* @param compareMode the compare mode used when checking * @param compareMode the compare mode used when checking
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is equal to the given one
*/ */
public JsonContentAssert isNotEqualToJson(CharSequence expected, public JsonContentAssert isNotEqualToJson(CharSequence expected,
JSONCompareMode compareMode) throws IOException { JSONCompareMode compareMode) {
String expectedJson = this.loader.getJson(expected); String expectedJson = this.loader.getJson(expected);
return assertNotPassed(compare(expectedJson, compareMode)); return assertNotPassed(compare(expectedJson, compareMode));
} }
...@@ -658,11 +632,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -658,11 +632,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param resourceLoadClass the source class used to load the resource * @param resourceLoadClass the source class used to load the resource
* @param compareMode the compare mode used when checking * @param compareMode the compare mode used when checking
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is equal to the given one
*/ */
public JsonContentAssert isNotEqualToJson(String path, Class<?> resourceLoadClass, public JsonContentAssert isNotEqualToJson(String path, Class<?> resourceLoadClass,
JSONCompareMode compareMode) throws IOException { JSONCompareMode compareMode) {
String expectedJson = this.loader.getJson(path, resourceLoadClass); String expectedJson = this.loader.getJson(path, resourceLoadClass);
return assertNotPassed(compare(expectedJson, compareMode)); return assertNotPassed(compare(expectedJson, compareMode));
} }
...@@ -672,11 +646,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -672,11 +646,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected the expected JSON bytes * @param expected the expected JSON bytes
* @param compareMode the compare mode used when checking * @param compareMode the compare mode used when checking
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is equal to the given one
*/ */
public JsonContentAssert isNotEqualToJson(byte[] expected, public JsonContentAssert isNotEqualToJson(byte[] expected,
JSONCompareMode compareMode) throws IOException { JSONCompareMode compareMode) {
String expectedJson = this.loader.getJson(expected); String expectedJson = this.loader.getJson(expected);
return assertNotPassed(compare(expectedJson, compareMode)); return assertNotPassed(compare(expectedJson, compareMode));
} }
...@@ -686,11 +660,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -686,11 +660,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected a file containing the expected JSON * @param expected a file containing the expected JSON
* @param compareMode the compare mode used when checking * @param compareMode the compare mode used when checking
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is equal to the given one
*/ */
public JsonContentAssert isNotEqualToJson(File expected, JSONCompareMode compareMode) public JsonContentAssert isNotEqualToJson(File expected,
throws IOException { JSONCompareMode compareMode) {
String expectedJson = this.loader.getJson(expected); String expectedJson = this.loader.getJson(expected);
return assertNotPassed(compare(expectedJson, compareMode)); return assertNotPassed(compare(expectedJson, compareMode));
} }
...@@ -700,11 +674,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -700,11 +674,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected an input stream containing the expected JSON * @param expected an input stream containing the expected JSON
* @param compareMode the compare mode used when checking * @param compareMode the compare mode used when checking
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is equal to the given one
*/ */
public JsonContentAssert isNotEqualToJson(InputStream expected, public JsonContentAssert isNotEqualToJson(InputStream expected,
JSONCompareMode compareMode) throws IOException { JSONCompareMode compareMode) {
String expectedJson = this.loader.getJson(expected); String expectedJson = this.loader.getJson(expected);
return assertNotPassed(compare(expectedJson, compareMode)); return assertNotPassed(compare(expectedJson, compareMode));
} }
...@@ -714,11 +688,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -714,11 +688,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected a resource containing the expected JSON * @param expected a resource containing the expected JSON
* @param compareMode the compare mode used when checking * @param compareMode the compare mode used when checking
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is equal to the given one
*/ */
public JsonContentAssert isNotEqualToJson(Resource expected, public JsonContentAssert isNotEqualToJson(Resource expected,
JSONCompareMode compareMode) throws IOException { JSONCompareMode compareMode) {
String expectedJson = this.loader.getJson(expected); String expectedJson = this.loader.getJson(expected);
return assertNotPassed(compare(expectedJson, compareMode)); return assertNotPassed(compare(expectedJson, compareMode));
} }
...@@ -731,11 +705,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -731,11 +705,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* JSON * JSON
* @param comparator the comparator used when checking * @param comparator the comparator used when checking
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is equal to the given one
*/ */
public JsonContentAssert isNotEqualToJson(CharSequence expected, public JsonContentAssert isNotEqualToJson(CharSequence expected,
JSONComparator comparator) throws IOException { JSONComparator comparator) {
String expectedJson = this.loader.getJson(expected); String expectedJson = this.loader.getJson(expected);
return assertNotPassed(compare(expectedJson, comparator)); return assertNotPassed(compare(expectedJson, comparator));
} }
...@@ -746,11 +720,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -746,11 +720,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param resourceLoadClass the source class used to load the resource * @param resourceLoadClass the source class used to load the resource
* @param comparator the comparator used when checking * @param comparator the comparator used when checking
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is equal to the given one
*/ */
public JsonContentAssert isNotEqualToJson(String path, Class<?> resourceLoadClass, public JsonContentAssert isNotEqualToJson(String path, Class<?> resourceLoadClass,
JSONComparator comparator) throws IOException { JSONComparator comparator) {
String expectedJson = this.loader.getJson(path, resourceLoadClass); String expectedJson = this.loader.getJson(path, resourceLoadClass);
return assertNotPassed(compare(expectedJson, comparator)); return assertNotPassed(compare(expectedJson, comparator));
} }
...@@ -760,11 +734,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -760,11 +734,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected the expected JSON bytes * @param expected the expected JSON bytes
* @param comparator the comparator used when checking * @param comparator the comparator used when checking
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is equal to the given one
*/ */
public JsonContentAssert isNotEqualToJson(byte[] expected, JSONComparator comparator) public JsonContentAssert isNotEqualToJson(byte[] expected,
throws IOException { JSONComparator comparator) {
String expectedJson = this.loader.getJson(expected); String expectedJson = this.loader.getJson(expected);
return assertNotPassed(compare(expectedJson, comparator)); return assertNotPassed(compare(expectedJson, comparator));
} }
...@@ -774,11 +748,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -774,11 +748,10 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected a file containing the expected JSON * @param expected a file containing the expected JSON
* @param comparator the comparator used when checking * @param comparator the comparator used when checking
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is equal to the given one
*/ */
public JsonContentAssert isNotEqualToJson(File expected, JSONComparator comparator) public JsonContentAssert isNotEqualToJson(File expected, JSONComparator comparator) {
throws IOException {
String expectedJson = this.loader.getJson(expected); String expectedJson = this.loader.getJson(expected);
return assertNotPassed(compare(expectedJson, comparator)); return assertNotPassed(compare(expectedJson, comparator));
} }
...@@ -788,11 +761,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -788,11 +761,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected an input stream containing the expected JSON * @param expected an input stream containing the expected JSON
* @param comparator the comparator used when checking * @param comparator the comparator used when checking
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is equal to the given one
*/ */
public JsonContentAssert isNotEqualToJson(InputStream expected, public JsonContentAssert isNotEqualToJson(InputStream expected,
JSONComparator comparator) throws IOException { JSONComparator comparator) {
String expectedJson = this.loader.getJson(expected); String expectedJson = this.loader.getJson(expected);
return assertNotPassed(compare(expectedJson, comparator)); return assertNotPassed(compare(expectedJson, comparator));
} }
...@@ -802,11 +775,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq ...@@ -802,11 +775,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
* @param expected a resource containing the expected JSON * @param expected a resource containing the expected JSON
* @param comparator the comparator used when checking * @param comparator the comparator used when checking
* @return {@code this} assertion object * @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 * @throws AssertionError if the actual JSON value is equal to the given one
*/ */
public JsonContentAssert isNotEqualToJson(Resource expected, public JsonContentAssert isNotEqualToJson(Resource expected,
JSONComparator comparator) throws IOException { JSONComparator comparator) {
String expectedJson = this.loader.getJson(expected); String expectedJson = this.loader.getJson(expected);
return assertNotPassed(compare(expectedJson, comparator)); return assertNotPassed(compare(expectedJson, comparator));
} }
......
...@@ -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