本文整理匯總了Java中com.android.volley.toolbox.NoCache類的典型用法代碼示例。如果您正苦於以下問題:Java NoCache類的具體用法?Java NoCache怎麽用?Java NoCache使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
NoCache類屬於com.android.volley.toolbox包,在下文中一共展示了NoCache類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: cancelAll_onlyCorrectTag
import com.android.volley.toolbox.NoCache; //導入依賴的package包/類
@Test public void cancelAll_onlyCorrectTag() throws Exception {
RequestQueue queue = new RequestQueue(new NoCache(), mMockNetwork, 0, mDelivery);
Object tagA = new Object();
Object tagB = new Object();
Request req1 = mock(Request.class);
when(req1.getTag()).thenReturn(tagA);
Request req2 = mock(Request.class);
when(req2.getTag()).thenReturn(tagB);
Request req3 = mock(Request.class);
when(req3.getTag()).thenReturn(tagA);
Request req4 = mock(Request.class);
when(req4.getTag()).thenReturn(tagA);
queue.add(req1); // A
queue.add(req2); // B
queue.add(req3); // A
queue.cancelAll(tagA);
queue.add(req4); // A
verify(req1).cancel(); // A cancelled
verify(req3).cancel(); // A cancelled
verify(req2, never()).cancel(); // B not cancelled
verify(req4, never()).cancel(); // A added after cancel not cancelled
}
示例2: add_requestFinishedListenerCanceled
import com.android.volley.toolbox.NoCache; //導入依賴的package包/類
/**
* Verify RequestFinishedListeners are informed when requests are canceled
*
* Needs to be an integration test because relies on Request -> dispatcher -> RequestQueue interaction
*/
@Test public void add_requestFinishedListenerCanceled() throws Exception {
RequestFinishedListener listener = mock(RequestFinishedListener.class);
Request request = new MockRequest();
Answer<NetworkResponse> delayAnswer = new Answer<NetworkResponse>() {
@Override
public NetworkResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
Thread.sleep(200);
return mock(NetworkResponse.class);
}
};
RequestQueue queue = new RequestQueue(new NoCache(), mMockNetwork, 1, mDelivery);
when(mMockNetwork.performRequest(request)).thenAnswer(delayAnswer);
queue.addRequestFinishedListener(listener);
queue.start();
queue.add(request);
request.cancel();
verify(listener, timeout(100)).onRequestFinished(request);
queue.stop();
}
示例3: add_requestFinishedListenerSuccess
import com.android.volley.toolbox.NoCache; //導入依賴的package包/類
/**
* Verify RequestFinishedListeners are informed when requests are successfully delivered
*
* Needs to be an integration test because relies on Request -> dispatcher -> RequestQueue interaction
*/
@Test public void add_requestFinishedListenerSuccess() throws Exception {
NetworkResponse response = mock(NetworkResponse.class);
Request request = new MockRequest();
RequestFinishedListener listener = mock(RequestFinishedListener.class);
RequestFinishedListener listener2 = mock(RequestFinishedListener.class);
RequestQueue queue = new RequestQueue(new NoCache(), mMockNetwork, 1, mDelivery);
queue.addRequestFinishedListener(listener);
queue.addRequestFinishedListener(listener2);
queue.start();
queue.add(request);
verify(listener, timeout(100)).onRequestFinished(request);
verify(listener2, timeout(100)).onRequestFinished(request);
queue.stop();
}
示例4: testAdd_requestProcessedInCorrectOrder
import com.android.volley.toolbox.NoCache; //導入依賴的package包/類
@UiThreadTest
public void testAdd_requestProcessedInCorrectOrder() throws Exception {
int requestsToMake = 100;
OrderCheckingNetwork network = new OrderCheckingNetwork();
RequestQueue queue = new RequestQueue(new NoCache(), network, 1, mDelivery);
for (Request<?> request : makeRequests(requestsToMake)) {
queue.add(request);
}
network.setExpectedRequests(requestsToMake);
queue.start();
network.waitUntilExpectedDone(2000); // 2 seconds
queue.stop();
}
示例5: testAdd_dedupeByCacheKey
import com.android.volley.toolbox.NoCache; //導入依賴的package包/類
public void testAdd_dedupeByCacheKey() throws Exception {
OrderCheckingNetwork network = new OrderCheckingNetwork();
final AtomicInteger parsed = new AtomicInteger();
final AtomicInteger delivered = new AtomicInteger();
// Enqueue 2 requests with the same cache key. The first request takes 1.5s. Assert that the
// second request is only handled after the first one has been parsed and delivered.
DelayedRequest req1 = new DelayedRequest(1500, parsed, delivered);
DelayedRequest req2 = new DelayedRequest(0, parsed, delivered) {
@Override
protected Response<Object> parseNetworkResponse(NetworkResponse response) {
assertEquals(1, parsed.get()); // req1 must have been parsed.
assertEquals(1, delivered.get()); // req1 must have been parsed.
return super.parseNetworkResponse(response);
}
};
network.setExpectedRequests(2);
RequestQueue queue = new RequestQueue(new NoCache(), network, 3, mDelivery);
queue.add(req1);
queue.add(req2);
queue.start();
network.waitUntilExpectedDone(2000);
queue.stop();
}
示例6: testCancelAll_onlyCorrectTag
import com.android.volley.toolbox.NoCache; //導入依賴的package包/類
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
}
示例7: getRequestQueue
import com.android.volley.toolbox.NoCache; //導入依賴的package包/類
public RequestQueue getRequestQueue() {
if (requestQueue == null) {
// getApplicationContext() is key, it keeps you from leaking the
// Activity or BroadcastReceiver if someone passes one in.
if (ctx == null) {
requestQueue = new RequestQueue(new NoCache(), new BasicNetwork(new OkHttp3Stack()));
} else {
if (StringUtils.isBlank(trustedHostname)) {
requestQueue = Volley.newRequestQueue(ctx.getApplicationContext(),
new OkHttp3Stack());
} else {
requestQueue = Volley.newRequestQueue(ctx.getApplicationContext(),
new OkHttp3Stack(ClientUtils.newCustomSocketFactory(trustedHostname)));
}
}
}
return requestQueue;
}