FileDocCategorySizeDatePackage
CacheDispatcherTest.javaAPI DocAndroid 5.1 API4312Thu Mar 12 22:22:56 GMT 2015com.android.volley

CacheDispatcherTest

public class CacheDispatcherTest extends TestCase

Fields Summary
private CacheDispatcher
mDispatcher
private com.android.volley.mock.WaitableQueue
mCacheQueue
private com.android.volley.mock.WaitableQueue
mNetworkQueue
private com.android.volley.mock.MockCache
mCache
private com.android.volley.mock.MockResponseDelivery
mDelivery
private com.android.volley.mock.MockRequest
mRequest
private static final long
TIMEOUT_MILLIS
Constructors Summary
Methods Summary
protected voidsetUp()


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

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

        mCacheQueue.add(mRequest);
        mCacheQueue.waitUntilEmpty(TIMEOUT_MILLIS);
        assertFalse(mDelivery.wasEitherResponseCalled());
        assertTrue(mNetworkQueue.size() > 0);
        Request request = mNetworkQueue.take();
        assertNull(request.getCacheEntry());
    
public voidtestCancelledRequest()

        mRequest.cancel();
        mCacheQueue.add(mRequest);
        mCacheQueue.waitUntilEmpty(TIMEOUT_MILLIS);
        assertFalse(mCache.getCalled);
        assertFalse(mDelivery.wasEitherResponseCalled());
    
public voidtestExpiredCacheHit()

        Cache.Entry entry = CacheTestUtils.makeRandomCacheEntry(null, true, true);
        mCache.setEntryToReturn(entry);
        mCacheQueue.add(mRequest);
        mCacheQueue.waitUntilEmpty(TIMEOUT_MILLIS);
        assertFalse(mDelivery.wasEitherResponseCalled());
        assertTrue(mNetworkQueue.size() > 0);
        Request request = mNetworkQueue.take();
        assertSame(entry, request.getCacheEntry());
    
public voidtestNonExpiredCacheHit()

        Cache.Entry entry = CacheTestUtils.makeRandomCacheEntry(null, false, false);
        mCache.setEntryToReturn(entry);
        mCacheQueue.add(mRequest);
        mCacheQueue.waitUntilEmpty(TIMEOUT_MILLIS);
        assertTrue(mDelivery.postResponse_called);
        assertFalse(mDelivery.postError_called);
    
public voidtestSoftExpiredCacheHit()

        Cache.Entry entry = CacheTestUtils.makeRandomCacheEntry(null, false, true);
        mCache.setEntryToReturn(entry);
        mCacheQueue.add(mRequest);
        mCacheQueue.waitUntilEmpty(TIMEOUT_MILLIS);
        assertTrue(mDelivery.postResponse_called);
        assertFalse(mDelivery.postError_called);
        assertTrue(mNetworkQueue.size() > 0);
        Request request = mNetworkQueue.take();
        assertSame(entry, request.getCacheEntry());