public void testCancelAll_onlyCorrectTag() throws Exception { MockNetwork network = new MockNetwork(); RequestQueue queue = new RequestQueue(new NoCache(), network, 3, mDelivery); Object tagA = new Object(); Object tagB = new Object(); MockRequest req1 = new MockRequest(); req1.setTag(tagA); MockRequest req2 = new MockRequest(); req2.setTag(tagB); MockRequest req3 = new MockRequest(); req3.setTag(tagA); MockRequest req4 = new MockRequest(); req4.setTag(tagA); queue.add(req1); // A queue.add(req2); // B queue.add(req3); // A queue.cancelAll(tagA); queue.add(req4); // A assertTrue(req1.cancel_called); // A cancelled assertFalse(req2.cancel_called); // B not cancelled assertTrue(req3.cancel_called); // A cancelled assertFalse(req4.cancel_called); // A added after cancel not cancelled }
@Before public void setUp() throws Exception { mDelivery = new MockResponseDelivery(); mNetworkQueue = new WaitableQueue(); mNetwork = new MockNetwork(); mCache = new MockCache(); mRequest = new MockRequest(); mDispatcher = new NetworkDispatcher(mNetworkQueue, mNetwork, mCache, mDelivery); mDispatcher.start(); }
@Test public void exceptionPostsError() throws Exception { mNetwork.setNumExceptionsToThrow(MockNetwork.ALWAYS_THROW_EXCEPTIONS); mNetworkQueue.add(mRequest); mNetworkQueue.waitUntilEmpty(TIMEOUT_MILLIS); assertFalse(mDelivery.postResponse_called); assertTrue(mDelivery.postError_called); }
@Override protected void setUp() throws Exception { 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(); }
public void testExceptionPostsError() throws Exception { mNetwork.setNumExceptionsToThrow(MockNetwork.ALWAYS_THROW_EXCEPTIONS); mNetworkQueue.add(mRequest); mNetworkQueue.waitUntilEmpty(TIMEOUT_MILLIS); assertFalse(mDelivery.postResponse_called); assertTrue(mDelivery.postError_called); }