1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.volley.mock; 18 19 import com.android.volley.Request; 20 import com.android.volley.Response; 21 import com.android.volley.ResponseDelivery; 22 import com.android.volley.VolleyError; 23 24 public class MockResponseDelivery implements ResponseDelivery { 25 26 public boolean postResponse_called = false; 27 public boolean postError_called = false; 28 public long postResponse_calledNtimes = 0; 29 30 public boolean wasEitherResponseCalled() { 31 return postResponse_called || postError_called; 32 } 33 34 public Response<?> responsePosted = null; 35 @Override 36 public void postResponse(Request<?> request, Response<?> response) { 37 postResponse_called = true; 38 postResponse_calledNtimes++; 39 responsePosted = response; 40 } 41 42 @Override 43 public void postResponse(Request<?> request, Response<?> response, Runnable runnable) { 44 postResponse_called = true; 45 postResponse_calledNtimes++; 46 responsePosted = response; 47 runnable.run(); 48 } 49 50 @Override 51 public void postError(Request<?> request, VolleyError error) { 52 postError_called = true; 53 } 54 } 55