android.util.MalformedJsonException Java Examples

The following examples show how to use android.util.MalformedJsonException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: android-galaxyzoo   Author: murraycu   File: ZooniverseClientTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testLoginWithFailure() throws IOException {
    final MockWebServer server = new MockWebServer();


    //On failure, the server's response code is HTTP_OK,
    //but it has a "success: false" parameter.
    final MockResponse response = new MockResponse();
    response.setResponseCode(HttpURLConnection.HTTP_OK);
    response.setBody("test nonsense failure message");
    server.enqueue(response);
    server.start();

    final ZooniverseClient client = createZooniverseClient(server);


    try {
        final LoginUtils.LoginResult result = client.loginSync("testusername", "testpassword");
        assertNotNull(result);
        assertFalse(result.getSuccess());
    } catch (final ZooniverseClient.LoginException e) {
        assertTrue(e.getCause() instanceof MalformedJsonException);
    }



    server.shutdown();
}
 
Example #2
Source Project: 365browser   Author: mogoweb   File: JsonSanitizer.java    License: Apache License 2.0 4 votes vote down vote up
private static String sanitizeString(String string) throws MalformedJsonException {
    if (!checkString(string)) {
        throw new MalformedJsonException("Invalid escape sequence");
    }
    return string;
}