下面列出了怎么用android.util.MalformedJsonException的API类实例代码及写法,或者点击链接到github查看源代码。
@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();
}
private static String sanitizeString(String string) throws MalformedJsonException {
if (!checkString(string)) {
throw new MalformedJsonException("Invalid escape sequence");
}
return string;
}