本文整理汇总了Java中com.android.volley.mock.MockRequest类的典型用法代码示例。如果您正苦于以下问题:Java MockRequest类的具体用法?Java MockRequest怎么用?Java MockRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MockRequest类属于com.android.volley.mock包,在下文中一共展示了MockRequest类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: add_requestFinishedListenerCanceled
import com.android.volley.mock.MockRequest; //导入依赖的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();
}
示例2: add_requestFinishedListenerSuccess
import com.android.volley.mock.MockRequest; //导入依赖的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();
}
示例3: testCancelAll_onlyCorrectTag
import com.android.volley.mock.MockRequest; //导入依赖的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
}
示例4: add_requestFinishedListenerCanceled
import com.android.volley.mock.MockRequest; //导入依赖的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();
}
示例5: add_requestFinishedListenerSuccess
import com.android.volley.mock.MockRequest; //导入依赖的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();
}