FileDocCategorySizeDatePackage
NetworkDispatcherTest.javaAPI DocAndroid 5.1 API3620Thu Mar 12 22:22:56 GMT 2015com.android.volley

NetworkDispatcherTest

public class NetworkDispatcherTest extends TestCase

Fields Summary
private NetworkDispatcher
mDispatcher
private com.android.volley.mock.MockResponseDelivery
mDelivery
private com.android.volley.mock.WaitableQueue
mNetworkQueue
private com.android.volley.mock.MockNetwork
mNetwork
private com.android.volley.mock.MockCache
mCache
private com.android.volley.mock.MockRequest
mRequest
private static final byte[]
CANNED_DATA
private static final long
TIMEOUT_MILLIS
Constructors Summary
Methods Summary
protected voidsetUp()


    
         
        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();
    
protected voidtearDown()

        super.tearDown();
        mDispatcher.quit();
        mDispatcher.join();
    
public voidtestExceptionPostsError()

        mNetwork.setNumExceptionsToThrow(MockNetwork.ALWAYS_THROW_EXCEPTIONS);
        mNetworkQueue.add(mRequest);
        mNetworkQueue.waitUntilEmpty(TIMEOUT_MILLIS);
        assertFalse(mDelivery.postResponse_called);
        assertTrue(mDelivery.postError_called);
    
public voidtestSuccessPostsResponse()

        mNetwork.setDataToReturn(CANNED_DATA);
        mNetwork.setNumExceptionsToThrow(0);
        mNetworkQueue.add(mRequest);
        mNetworkQueue.waitUntilEmpty(TIMEOUT_MILLIS);
        assertFalse(mDelivery.postError_called);
        assertTrue(mDelivery.postResponse_called);
        Response<?> response = mDelivery.responsePosted;
        assertNotNull(response);
        assertTrue(response.isSuccess());
        assertTrue(Arrays.equals((byte[])response.result, CANNED_DATA));
    
public voidtest_shouldCacheFalse()

        mRequest.setShouldCache(false);
        mNetworkQueue.add(mRequest);
        mNetworkQueue.waitUntilEmpty(TIMEOUT_MILLIS);
        assertFalse(mCache.putCalled);
    
public voidtest_shouldCacheTrue()

        mNetwork.setDataToReturn(CANNED_DATA);
        mRequest.setShouldCache(true);
        mRequest.setCacheKey("bananaphone");
        mNetworkQueue.add(mRequest);
        mNetworkQueue.waitUntilEmpty(TIMEOUT_MILLIS);
        assertTrue(mCache.putCalled);
        assertNotNull(mCache.entryPut);
        assertTrue(Arrays.equals(mCache.entryPut.data, CANNED_DATA));
        assertEquals("bananaphone", mCache.keyPut);