use of com.lonepulse.robozombie.proxy.InvocationException in project RoboZombie by sahan.
the class AsyncEndpointTest method testAsyncErrorCallbackError.
/**
* <p>Tests an erroneous asynchronous request where the implementation of the
* {@link AsyncHandler#onError(Exception)} callback throws an exception.</p>
*
* @since 1.3.0
*/
@Test
public final void testAsyncErrorCallbackError() throws InterruptedException {
Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
String subpath = "/errorcallbackerror", body = "non-JSON-content";
stubFor(get(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200).withBody(body)));
final Lock lock = new ReentrantLock();
final Condition condition = lock.newCondition();
asyncEndpoint.asyncErrorCallbackError(new AsyncHandler<User>() {
@Override
public void onSuccess(HttpResponse httpResponse, User user) {
}
@Override
public void onError(InvocationException error) {
try {
throw new IllegalStateException();
} finally {
lock.lock();
condition.signal();
lock.unlock();
}
}
});
lock.lock();
condition.await();
lock.unlock();
verify(getRequestedFor(urlEqualTo(subpath)));
//verify that the asynchronous request executor has survived the exception
successScenario();
}
use of com.lonepulse.robozombie.proxy.InvocationException in project RoboZombie by sahan.
the class AsyncEndpointTest method testAsyncError.
/**
* <p>Tests asynchronous request execution with @{@link Async} and
* {@link AsyncHandler#onError(Exception)}.</p>
*
* @since 1.3.0
*/
@Test
public final void testAsyncError() throws InterruptedException {
Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
String subpath = "/asyncerror", body = "non-JSON-content";
stubFor(get(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200).withBody(body)));
final Object[] content = new Object[1];
final Lock lock = new ReentrantLock();
final Condition condition = lock.newCondition();
asyncEndpoint.asyncError(new AsyncHandler<User>() {
@Override
public void onSuccess(HttpResponse httpResponse, User user) {
}
@Override
public void onError(InvocationException error) {
lock.lock();
content[0] = error;
condition.signal();
lock.unlock();
}
});
lock.lock();
condition.await();
lock.unlock();
verify(getRequestedFor(urlEqualTo(subpath)));
assertTrue(content[0] != null);
assertTrue(content[0] instanceof InvocationException);
}
Aggregations