Search in sources :

Example 16 with MockRequest

use of com.android.volley.mock.MockRequest in project iosched by google.

the class CacheDispatcherTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mCacheQueue = new WaitableQueue();
    mNetworkQueue = new WaitableQueue();
    mCache = new MockCache();
    mDelivery = new MockResponseDelivery();
    mRequest = new MockRequest();
    mDispatcher = new CacheDispatcher(mCacheQueue, mNetworkQueue, mCache, mDelivery);
    mDispatcher.start();
}
Also used : MockResponseDelivery(com.android.volley.mock.MockResponseDelivery) WaitableQueue(com.android.volley.mock.WaitableQueue) MockRequest(com.android.volley.mock.MockRequest) MockCache(com.android.volley.mock.MockCache)

Example 17 with MockRequest

use of com.android.volley.mock.MockRequest in project iosched by google.

the class NetworkDispatcherTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mDelivery = new MockResponseDelivery();
    mNetworkQueue = new WaitableQueue();
    mNetwork = new MockNetwork();
    mCache = new MockCache();
    mRequest = new MockRequest();
    mDispatcher = new NetworkDispatcher(mNetworkQueue, mNetwork, mCache, mDelivery);
    mDispatcher.start();
}
Also used : MockResponseDelivery(com.android.volley.mock.MockResponseDelivery) WaitableQueue(com.android.volley.mock.WaitableQueue) MockNetwork(com.android.volley.mock.MockNetwork) MockRequest(com.android.volley.mock.MockRequest) MockCache(com.android.volley.mock.MockCache)

Example 18 with MockRequest

use of com.android.volley.mock.MockRequest in project iosched by google.

the class RequestQueueTest method testCancelAll_onlyCorrectTag.

public void testCancelAll_onlyCorrectTag() throws Exception {
    MockNetwork network = new MockNetwork();
    RequestQueue queue = new RequestQueue(new NoCache(), network, 3, mDelivery);
    Object tagA = new Object();
    Object tagB = new Object();
    MockRequest req1 = new MockRequest();
    req1.setTag(tagA);
    MockRequest req2 = new MockRequest();
    req2.setTag(tagB);
    MockRequest req3 = new MockRequest();
    req3.setTag(tagA);
    MockRequest req4 = new MockRequest();
    req4.setTag(tagA);
    // A
    queue.add(req1);
    // B
    queue.add(req2);
    // A
    queue.add(req3);
    queue.cancelAll(tagA);
    // A
    queue.add(req4);
    // A cancelled
    assertTrue(req1.cancel_called);
    // B not cancelled
    assertFalse(req2.cancel_called);
    // A cancelled
    assertTrue(req3.cancel_called);
    // A added after cancel not cancelled
    assertFalse(req4.cancel_called);
}
Also used : MockNetwork(com.android.volley.mock.MockNetwork) MockRequest(com.android.volley.mock.MockRequest) NoCache(com.android.volley.toolbox.NoCache)

Example 19 with MockRequest

use of com.android.volley.mock.MockRequest in project iosched by google.

the class ResponseDeliveryTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    // 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);
}
Also used : ImmediateResponseDelivery(com.android.volley.utils.ImmediateResponseDelivery) MockRequest(com.android.volley.mock.MockRequest)

Example 20 with MockRequest

use of com.android.volley.mock.MockRequest in project FastDev4Android by jiangqqlmj.

the class RequestQueueIntegrationTest method add_requestFinishedListenerCanceled.

/**
     * Verify RequestFinishedListeners are informed when requests are canceled
     *
     * Needs to be an integration test because relies on Request -> dispatcher -> RequestQueue interaction
     */
@Test
public void add_requestFinishedListenerCanceled() throws Exception {
    RequestFinishedListener listener = mock(RequestFinishedListener.class);
    Request request = new MockRequest();
    Answer<NetworkResponse> delayAnswer = new Answer<NetworkResponse>() {

        @Override
        public NetworkResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
            Thread.sleep(200);
            return mock(NetworkResponse.class);
        }
    };
    RequestQueue queue = new RequestQueue(new NoCache(), mMockNetwork, 1, mDelivery);
    when(mMockNetwork.performRequest(request)).thenAnswer(delayAnswer);
    queue.addRequestFinishedListener(listener);
    queue.start();
    queue.add(request);
    request.cancel();
    verify(listener, timeout(100)).onRequestFinished(request);
    queue.stop();
}
Also used : Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MockRequest(com.android.volley.mock.MockRequest) MockRequest(com.android.volley.mock.MockRequest) NoCache(com.android.volley.toolbox.NoCache) RequestFinishedListener(com.android.volley.RequestQueue.RequestFinishedListener) Test(org.junit.Test)

Aggregations

MockRequest (com.android.volley.mock.MockRequest)29 NoCache (com.android.volley.toolbox.NoCache)16 RequestFinishedListener (com.android.volley.RequestQueue.RequestFinishedListener)15 Test (org.junit.Test)15 Before (org.junit.Before)9 InvocationOnMock (org.mockito.invocation.InvocationOnMock)9 Answer (org.mockito.stubbing.Answer)9 MockCache (com.android.volley.mock.MockCache)8 MockResponseDelivery (com.android.volley.mock.MockResponseDelivery)8 WaitableQueue (com.android.volley.mock.WaitableQueue)8 MockNetwork (com.android.volley.mock.MockNetwork)5 ImmediateResponseDelivery (com.android.volley.utils.ImmediateResponseDelivery)4 Priority (com.android.volley.Request.Priority)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1