CallerInfoAsyncQueryFactoryFixture.java revision f7a0897fa1fc5e759505500b690267ad14d860c0
1/*
2 * Copyright (C) 2015 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
17package com.android.server.telecom.tests;
18
19import com.android.internal.telephony.CallerInfo;
20import com.android.internal.telephony.CallerInfoAsyncQuery;
21import com.android.server.telecom.CallerInfoAsyncQueryFactory;
22import com.android.server.telecom.Log;
23
24import android.content.Context;
25
26import java.util.ArrayList;
27import java.util.Collections;
28import java.util.List;
29
30/**
31 * Controls a test {@link CallerInfoAsyncQueryFactory} to abstract away the asynchronous retrieval
32 * of caller information from the Android contacts database.
33 */
34public class CallerInfoAsyncQueryFactoryFixture implements
35        TestFixture<CallerInfoAsyncQueryFactory> {
36
37    static class Request {
38        int mToken;
39        Object mCookie;
40        CallerInfoAsyncQuery.OnQueryCompleteListener mListener;
41        void reply() {
42            mListener.onQueryComplete(mToken, mCookie, new CallerInfo());
43        }
44    }
45
46    CallerInfoAsyncQueryFactory mCallerInfoAsyncQueryFactory = new CallerInfoAsyncQueryFactory() {
47        @Override
48        public CallerInfoAsyncQuery startQuery(int token, Context context, String number,
49                CallerInfoAsyncQuery.OnQueryCompleteListener listener, Object cookie) {
50            Request r = new Request();
51            r.mToken = token;
52            r.mCookie = cookie;
53            r.mListener = listener;
54            mRequests.add(r);
55            return null;
56        }
57    };
58
59    final List<Request> mRequests = Collections.synchronizedList(new ArrayList<Request>());
60
61    public CallerInfoAsyncQueryFactoryFixture() throws Exception {
62        Log.i(this, "Creating ...");
63    }
64
65    @Override
66    public CallerInfoAsyncQueryFactory getTestDouble() {
67        return mCallerInfoAsyncQueryFactory;
68    }
69}
70