当前位置: 首页>>代码示例>>Java>>正文


Java RequestFinishedListener类代码示例

本文整理汇总了Java中com.android.volley.RequestQueue.RequestFinishedListener的典型用法代码示例。如果您正苦于以下问题:Java RequestFinishedListener类的具体用法?Java RequestFinishedListener怎么用?Java RequestFinishedListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RequestFinishedListener类属于com.android.volley.RequestQueue包,在下文中一共展示了RequestFinishedListener类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: add_requestFinishedListenerCanceled

import com.android.volley.RequestQueue.RequestFinishedListener; //导入依赖的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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:28,代码来源:RequestQueueIntegrationTest.java

示例2: add_requestFinishedListenerSuccess

import com.android.volley.RequestQueue.RequestFinishedListener; //导入依赖的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();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:RequestQueueIntegrationTest.java

示例3: add_requestFinishedListenerCanceled

import com.android.volley.RequestQueue.RequestFinishedListener; //导入依赖的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();
}
 
开发者ID:CaMnter,项目名称:SaveVolley,代码行数:29,代码来源:RequestQueueIntegrationTest.java

示例4: add_requestFinishedListenerSuccess

import com.android.volley.RequestQueue.RequestFinishedListener; //导入依赖的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();
}
 
开发者ID:CaMnter,项目名称:SaveVolley,代码行数:24,代码来源:RequestQueueIntegrationTest.java


注:本文中的com.android.volley.RequestQueue.RequestFinishedListener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。