Methods Summary |
---|
protected void | setUp()
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 void | tearDown()
super.tearDown();
mDispatcher.quit();
mDispatcher.join();
|
public void | testExceptionPostsError()
mNetwork.setNumExceptionsToThrow(MockNetwork.ALWAYS_THROW_EXCEPTIONS);
mNetworkQueue.add(mRequest);
mNetworkQueue.waitUntilEmpty(TIMEOUT_MILLIS);
assertFalse(mDelivery.postResponse_called);
assertTrue(mDelivery.postError_called);
|
public void | testSuccessPostsResponse()
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 void | test_shouldCacheFalse()
mRequest.setShouldCache(false);
mNetworkQueue.add(mRequest);
mNetworkQueue.waitUntilEmpty(TIMEOUT_MILLIS);
assertFalse(mCache.putCalled);
|
public void | test_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);
|