Skip to content

Instantly share code, notes, and snippets.

@m-x-k
Created July 20, 2016 13:51
Show Gist options
  • Save m-x-k/8e6069a94ee36614e7adcebf616417ee to your computer and use it in GitHub Desktop.
Save m-x-k/8e6069a94ee36614e7adcebf616417ee to your computer and use it in GitHub Desktop.
Simple java json utils for testing
import com.google.gson.Gson;
import org.skyscreamer.jsonassert.JSONAssert;
import static org.junit.Assert.fail;
public final class JSONUtils {
private static final Gson gson = new Gson();
public static void assertValidJson(String jsonInString) {
try {
gson.fromJson(jsonInString, Object.class);
} catch(com.google.gson.JsonSyntaxException ex) {
fail(ex.getMessage());
}
}
public static void assertJSONContains(String expected, String actual) {
try {
JSONAssert.assertEquals(expected, actual, false);
} catch (Exception e) {
fail(e.getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment