Java Code Examples for com.android.volley.utils.CacheTestUtils#makeRandomCacheEntry()

The following examples show how to use com.android.volley.utils.CacheTestUtils#makeRandomCacheEntry() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: volley   File: CacheDispatcherTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void softExpiredCacheHit() throws Exception {
    Cache.Entry entry = CacheTestUtils.makeRandomCacheEntry(null, false, true);
    when(mCache.get(anyString())).thenReturn(entry);
    mDispatcher.processRequest(mRequest);

    // Soft expiration needs to use the deferred Runnable variant of postResponse,
    // so make sure it gets to run.
    ArgumentCaptor<Runnable> runnable = ArgumentCaptor.forClass(Runnable.class);
    verify(mDelivery).postResponse(any(Request.class), any(Response.class), runnable.capture());
    runnable.getValue().run();
    // This way we can verify the behavior of the Runnable as well.
    verify(mNetworkQueue).put(mRequest);
    assertSame(entry, mRequest.getCacheEntry());

    verify(mDelivery, never()).postError(any(Request.class), any(VolleyError.class));
}
 
Example 2
Source Project: volley   File: CacheDispatcherTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void processRequestNotifiesListener() throws Exception {
    RequestQueue.RequestEventListener listener = mock(RequestQueue.RequestEventListener.class);
    RequestQueue queue = new RequestQueue(mCache, mNetwork, 0, mDelivery);
    queue.addRequestEventListener(listener);
    mRequest.setRequestQueue(queue);

    Cache.Entry entry = CacheTestUtils.makeRandomCacheEntry(null, false, false);
    when(mCache.get(anyString())).thenReturn(entry);
    mDispatcher.processRequest(mRequest);

    InOrder inOrder = inOrder(listener);
    inOrder.verify(listener)
            .onRequestEvent(mRequest, RequestQueue.RequestEvent.REQUEST_CACHE_LOOKUP_STARTED);
    inOrder.verify(listener)
            .onRequestEvent(mRequest, RequestQueue.RequestEvent.REQUEST_CACHE_LOOKUP_FINISHED);
    inOrder.verifyNoMoreInteractions();
}
 
Example 3
Source Project: product-emm   File: CacheDispatcherTest.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 4
Source Project: CrossBow   File: CacheDispatcherTest.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 5
Source Project: volley   File: CacheDispatcherTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void expiredCacheHit() throws Exception {
    Cache.Entry entry = CacheTestUtils.makeRandomCacheEntry(null, true, true);
    when(mCache.get(anyString())).thenReturn(entry);
    mDispatcher.processRequest(mRequest);
    verifyNoResponse(mDelivery);
    verify(mNetworkQueue).put(mRequest);
    assertSame(entry, mRequest.getCacheEntry());
}
 
Example 6
Source Project: CrossBow   File: ResponseDeliveryTest.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 7
Source Project: product-emm   File: CacheDispatcherTest.java    License: Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 8
Source Project: CrossBow   File: CacheDispatcherTest.java    License: Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 9
@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);
}
 
Example 10
Source Project: product-emm   File: CacheDispatcherTest.java    License: Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 11
@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);
}
 
Example 12
@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());
}
 
Example 13
Source Project: SaveVolley   File: ResponseDeliveryTest.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 14
@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);
}
 
Example 15
Source Project: SaveVolley   File: CacheDispatcherTest.java    License: Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 16
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());
}
 
Example 17
Source Project: product-emm   File: CacheDispatcherTest.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 18
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);
}
 
Example 19
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());
}
 
Example 20
Source Project: CrossBow   File: CacheDispatcherTest.java    License: Apache License 2.0 5 votes vote down vote up
@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());
}