use of com.android.volley.mock.MockRequest in project FastDev4Android by jiangqqlmj.
the class CacheDispatcherTest method setUp.
@Before
public void setUp() throws Exception {
mCacheQueue = new WaitableQueue();
mNetworkQueue = new WaitableQueue();
mCache = new MockCache();
mDelivery = new MockResponseDelivery();
mRequest = new MockRequest();
mDispatcher = new CacheDispatcher(mCacheQueue, mNetworkQueue, mCache, mDelivery);
mDispatcher.start();
}
use of com.android.volley.mock.MockRequest in project FastDev4Android by jiangqqlmj.
the class NetworkDispatcherTest method setUp.
@Before
public void setUp() throws Exception {
mDelivery = new MockResponseDelivery();
mNetworkQueue = new WaitableQueue();
mNetwork = new MockNetwork();
mCache = new MockCache();
mRequest = new MockRequest();
mDispatcher = new NetworkDispatcher(mNetworkQueue, mNetwork, mCache, mDelivery);
mDispatcher.start();
}
use of com.android.volley.mock.MockRequest in project FastDev4Android by jiangqqlmj.
the class RequestQueueIntegrationTest method add_requestFinishedListenerError.
/**
* Verify RequestFinishedListeners are informed when request errors
*
* Needs to be an integration test because relies on Request -> dispatcher -> RequestQueue interaction
*/
@Test
public void add_requestFinishedListenerError() throws Exception {
RequestFinishedListener listener = mock(RequestFinishedListener.class);
Request request = new MockRequest();
RequestQueue queue = new RequestQueue(new NoCache(), mMockNetwork, 1, mDelivery);
when(mMockNetwork.performRequest(request)).thenThrow(new VolleyError());
queue.addRequestFinishedListener(listener);
queue.start();
queue.add(request);
verify(listener, timeout(100)).onRequestFinished(request);
queue.stop();
}
use of com.android.volley.mock.MockRequest in project FastDev4Android by jiangqqlmj.
the class RequestQueueIntegrationTest method add_dedupeByCacheKey.
/**
* Asserts that requests with same cache key are processed in order.
*
* Needs to be an integration test because relies on complex interations between various queues
*/
@Test
public void add_dedupeByCacheKey() throws Exception {
// Enqueue 2 requests with the same cache key. The first request takes 20ms. Assert that the
// second request is only handled after the first one has been parsed and delivered.
Request req1 = new MockRequest();
Request req2 = new MockRequest();
RequestFinishedListener listener = mock(RequestFinishedListener.class);
Answer<NetworkResponse> delayAnswer = new Answer<NetworkResponse>() {
@Override
public NetworkResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
Thread.sleep(20);
return mock(NetworkResponse.class);
}
};
//delay only for first
when(mMockNetwork.performRequest(req1)).thenAnswer(delayAnswer);
when(mMockNetwork.performRequest(req2)).thenReturn(mock(NetworkResponse.class));
RequestQueue queue = new RequestQueue(new NoCache(), mMockNetwork, 3, mDelivery);
queue.addRequestFinishedListener(listener);
queue.add(req1);
queue.add(req2);
queue.start();
// you cannot do strict order verification with mockito 1.9.5 :(
// as an alternative, first verify no requests have finished, then verify req1 goes through
verifyNoMoreInteractions(listener);
verify(listener, timeout(100)).onRequestFinished(req1);
verify(listener, timeout(10)).onRequestFinished(req2);
queue.stop();
}
use of com.android.volley.mock.MockRequest in project FastDev4Android by jiangqqlmj.
the class ResponseDeliveryTest method setUp.
@Before
public void setUp() throws Exception {
// Make the delivery just run its posted responses immediately.
mDelivery = new ImmediateResponseDelivery();
mRequest = new MockRequest();
mRequest.setSequence(1);
byte[] data = new byte[16];
Cache.Entry cacheEntry = CacheTestUtils.makeRandomCacheEntry(data);
mSuccessResponse = Response.success(data, cacheEntry);
}
Aggregations