use of com.androidnetworking.interfaces.StringRequestListener in project Fast-Android-Networking by amitshekhariitbhu.
the class ApiTest method testUploadRequest404.
public void testUploadRequest404() throws InterruptedException {
server.enqueue(new MockResponse().setResponseCode(404).setBody("uploadTestResponse"));
final AtomicReference<String> errorDetailRef = new AtomicReference<>();
final AtomicReference<String> errorBodyRef = new AtomicReference<>();
final AtomicReference<Integer> errorCodeRef = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
AndroidNetworking.upload(server.url("/").toString()).addMultipartParameter("key", "value").build().getAsString(new StringRequestListener() {
@Override
public void onResponse(String response) {
assertTrue(false);
}
@Override
public void onError(ANError anError) {
errorBodyRef.set(anError.getErrorBody());
errorDetailRef.set(anError.getErrorDetail());
errorCodeRef.set(anError.getErrorCode());
latch.countDown();
}
});
assertTrue(latch.await(2, SECONDS));
assertEquals(ANConstants.RESPONSE_FROM_SERVER_ERROR, errorDetailRef.get());
assertEquals("uploadTestResponse", errorBodyRef.get());
assertEquals(404, errorCodeRef.get().intValue());
}
Aggregations