Created
July 20, 2016 13:51
-
-
Save m-x-k/8e6069a94ee36614e7adcebf616417ee to your computer and use it in GitHub Desktop.
Simple java json utils for testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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