use of com.octo.android.robospice.stub.RequestListenerWithProgressHistoryStub in project robospice by stephanenicolas.
the class SpiceManagerTest method test_should_receive_request_progress_updates_in_right_order.
public void test_should_receive_request_progress_updates_in_right_order() throws InterruptedException {
// TDD test for issue 36
// given
spiceManager.start(getContext());
SpiceRequestStub<String> spiceRequestStub = new SpiceRequestSucceedingStub<String>(TEST_CLASS, TEST_RETURNED_DATA);
RequestListenerWithProgressHistoryStub<String> requestListenerStub = new RequestListenerWithProgressHistoryStub<String>();
// when
spiceManager.execute(spiceRequestStub, TEST_CACHE_KEY, TEST_DURATION, requestListenerStub);
requestListenerStub.awaitComplete(REQUEST_COMPLETION_TIME_OUT);
requestListenerStub.await(REQUEST_COMPLETION_TIME_OUT);
// test
assertTrue(requestListenerStub.isComplete());
final int expectedRequestProgressCount = 4;
synchronized (requestListenerStub.getRequestProgressesHistory()) {
for (RequestProgress requestProgress : requestListenerStub.getRequestProgressesHistory()) {
Ln.d("RequestProgress received : %s", requestProgress.getStatus());
}
}
int progressStatusIndex = 0;
assertEquals(RequestStatus.PENDING, requestListenerStub.getRequestProgressesHistory().get(progressStatusIndex++).getStatus());
assertEquals(RequestStatus.LOADING_FROM_NETWORK, requestListenerStub.getRequestProgressesHistory().get(progressStatusIndex++).getStatus());
assertEquals(RequestStatus.WRITING_TO_CACHE, requestListenerStub.getRequestProgressesHistory().get(progressStatusIndex++).getStatus());
assertEquals(RequestStatus.COMPLETE, requestListenerStub.getRequestProgressesHistory().get(progressStatusIndex++).getStatus());
assertEquals(expectedRequestProgressCount, requestListenerStub.getRequestProgressesHistory().size());
assertTrue(requestListenerStub.isSuccessful());
}
Aggregations