com.android.volley.mock.MockNetwork Java Examples

The following examples show how to use com.android.volley.mock.MockNetwork. 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 File: RequestQueueTest.java    From android-project-wo2b with Apache License 2.0 6 votes vote down vote up
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
}
 
Example #2
Source File: RequestQueueTest.java    From android-discourse with Apache License 2.0 6 votes vote down vote up
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
}
 
Example #3
Source File: NetworkDispatcherTest.java    From device-database with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #4
Source File: NetworkDispatcherTest.java    From device-database with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #5
Source File: NetworkDispatcherTest.java    From SaveVolley with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #6
Source File: NetworkDispatcherTest.java    From SaveVolley with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #7
Source File: NetworkDispatcherTest.java    From android-project-wo2b with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #8
Source File: NetworkDispatcherTest.java    From android-project-wo2b with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #9
Source File: NetworkDispatcherTest.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #10
Source File: NetworkDispatcherTest.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #11
Source File: NetworkDispatcherTest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #12
Source File: NetworkDispatcherTest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #13
Source File: NetworkDispatcherTest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #14
Source File: NetworkDispatcherTest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #15
Source File: NetworkDispatcherTest.java    From CrossBow with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #16
Source File: NetworkDispatcherTest.java    From CrossBow with Apache License 2.0 5 votes vote down vote up
@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);
}