@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); }
@Test public void nonExpiredCacheHit() throws Exception { 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); }
@Test public void softExpiredCacheHit() throws Exception { 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()); }
@Test public void expiredCacheHit() throws Exception { 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()); }
@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); }
public void testNonExpiredCacheHit() throws Exception { 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 void testSoftExpiredCacheHit() throws Exception { 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()); }
public void testExpiredCacheHit() throws Exception { 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()); }