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


Java MockRequest.setCacheKey方法代码示例

本文整理汇总了Java中com.android.volley.mock.MockRequest.setCacheKey方法的典型用法代码示例。如果您正苦于以下问题:Java MockRequest.setCacheKey方法的具体用法?Java MockRequest.setCacheKey怎么用?Java MockRequest.setCacheKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.android.volley.mock.MockRequest的用法示例。


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

示例1: add_requestProcessedInCorrectOrder

import com.android.volley.mock.MockRequest; //导入方法依赖的package包/类
@Test public void add_requestProcessedInCorrectOrder() throws Exception {
    // Enqueue 2 requests with different cache keys, and different priorities. The second, higher priority request
    // takes 20ms.
    // Assert that first request is only handled after the first one has been parsed and delivered.
    MockRequest lowerPriorityReq = new MockRequest();
    MockRequest higherPriorityReq = new MockRequest();
    lowerPriorityReq.setCacheKey("1");
    higherPriorityReq.setCacheKey("2");
    lowerPriorityReq.setPriority(Priority.LOW);
    higherPriorityReq.setPriority(Priority.HIGH);

    RequestFinishedListener listener = mock(RequestFinishedListener.class);
    Answer<NetworkResponse> delayAnswer = new Answer<NetworkResponse>() {
        @Override
        public NetworkResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
            Thread.sleep(20);
            return mock(NetworkResponse.class);
        }
    };
    //delay only for higher request
    when(mMockNetwork.performRequest(higherPriorityReq)).thenAnswer(delayAnswer);
    when(mMockNetwork.performRequest(lowerPriorityReq)).thenReturn(mock(NetworkResponse.class));

    RequestQueue queue = new RequestQueue(new NoCache(), mMockNetwork, 1, mDelivery);
    queue.addRequestFinishedListener(listener);
    queue.add(lowerPriorityReq);
    queue.add(higherPriorityReq);
    queue.start();

    // you cannot do strict order verification in combination with timeouts with mockito 1.9.5 :(
    // as an alternative, first verify no requests have finished, while higherPriorityReq should be processing
    verifyNoMoreInteractions(listener);
    // verify higherPriorityReq goes through first
    verify(listener, timeout(100)).onRequestFinished(higherPriorityReq);
    // verify lowerPriorityReq goes last
    verify(listener, timeout(10)).onRequestFinished(lowerPriorityReq);
    queue.stop();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:39,代码来源:RequestQueueIntegrationTest.java

示例2: makeRequests

import com.android.volley.mock.MockRequest; //导入方法依赖的package包/类
/**
 * Make a list of requests with random priorities.
 * @param count Number of requests to make
 */
private List<MockRequest> makeRequests(int count) {
    Request.Priority[] allPriorities = Request.Priority.values();
    Random random = new Random();

    List<MockRequest> requests = new ArrayList<MockRequest>();
    for (int i = 0; i < count; i++) {
        MockRequest request = new MockRequest();
        Request.Priority priority = allPriorities[random.nextInt(allPriorities.length)];
        request.setCacheKey(String.valueOf(i));
        request.setPriority(priority);
        requests.add(request);
    }
    return requests;
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:19,代码来源:RequestQueueTest.java

示例3: add_requestProcessedInCorrectOrder

import com.android.volley.mock.MockRequest; //导入方法依赖的package包/类
@Test public void add_requestProcessedInCorrectOrder() throws Exception {
    // Enqueue 2 requests with different cache keys, and different priorities. The second, higher priority request
    // takes 20ms.
    // Assert that first request is only handled after the first one has been parsed and delivered.
    MockRequest lowerPriorityReq = new MockRequest();
    MockRequest higherPriorityReq = new MockRequest();
    lowerPriorityReq.setCacheKey("1");
    higherPriorityReq.setCacheKey("2");
    lowerPriorityReq.setPriority(Priority.LOW);
    higherPriorityReq.setPriority(Priority.HIGH);

    RequestFinishedListener listener = mock(RequestFinishedListener.class);
    Answer<NetworkResponse> delayAnswer = new Answer<NetworkResponse>() {
        @Override public NetworkResponse answer(InvocationOnMock invocationOnMock)
                throws Throwable {
            Thread.sleep(20);
            return mock(NetworkResponse.class);
        }
    };
    //delay only for higher request
    when(mMockNetwork.performRequest(higherPriorityReq)).thenAnswer(delayAnswer);
    when(mMockNetwork.performRequest(lowerPriorityReq)).thenReturn(mock(NetworkResponse.class));

    RequestQueue queue = new RequestQueue(new NoCache(), mMockNetwork, 1, mDelivery);
    queue.addRequestFinishedListener(listener);
    queue.add(lowerPriorityReq);
    queue.add(higherPriorityReq);
    queue.start();

    // you cannot do strict order verification in combination with timeouts with mockito 1.9.5 :(
    // as an alternative, first verify no requests have finished, while higherPriorityReq should be processing
    verifyNoMoreInteractions(listener);
    // verify higherPriorityReq goes through first
    verify(listener, timeout(100)).onRequestFinished(higherPriorityReq);
    // verify lowerPriorityReq goes last
    verify(listener, timeout(10)).onRequestFinished(lowerPriorityReq);
    queue.stop();
}
 
开发者ID:CaMnter,项目名称:SaveVolley,代码行数:39,代码来源:RequestQueueIntegrationTest.java

示例4: makeRequests

import com.android.volley.mock.MockRequest; //导入方法依赖的package包/类
/**
 * Make a list of requests with random priorities.
 *
 * @param count Number of requests to make
 */
private List<MockRequest> makeRequests(int count) {
    Request.Priority[] allPriorities = Request.Priority.values();
    Random random = new Random();

    List<MockRequest> requests = new ArrayList<MockRequest>();
    for (int i = 0; i < count; i++) {
        MockRequest request = new MockRequest();
        Request.Priority priority = allPriorities[random.nextInt(allPriorities.length)];
        request.setCacheKey(String.valueOf(i));
        request.setPriority(priority);
        requests.add(request);
    }
    return requests;
}
 
开发者ID:goodev,项目名称:android-discourse,代码行数:20,代码来源:RequestQueueTest.java


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