blob: 1ebf1709abd456ab37f7988508d634881d4f3c17 [file] [log] [blame]
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.server.telecom.tests;
import com.android.internal.telephony.CallerInfo;
import com.android.internal.telephony.CallerInfoAsyncQuery;
import com.android.server.telecom.CallerInfoAsyncQueryFactory;
import com.android.server.telecom.Log;
import android.content.Context;
import java.util.ArrayList;
import java.util.List;
/**
* Controls a test {@link CallerInfoAsyncQueryFactory} to abstract away the asynchronous retrieval
* of caller information from the Android contacts database.
*/
public class CallerInfoAsyncQueryFactoryFixture implements
TestFixture<CallerInfoAsyncQueryFactory> {
static class Request {
int mToken;
Object mCookie;
CallerInfoAsyncQuery.OnQueryCompleteListener mListener;
void reply() {
mListener.onQueryComplete(mToken, mCookie, new CallerInfo());
}
}
CallerInfoAsyncQueryFactory mCallerInfoAsyncQueryFactory = new CallerInfoAsyncQueryFactory() {
@Override
public CallerInfoAsyncQuery startQuery(int token, Context context, String number,
CallerInfoAsyncQuery.OnQueryCompleteListener listener, Object cookie) {
Request r = new Request();
r.mToken = token;
r.mCookie = cookie;
r.mListener = listener;
mRequests.add(r);
return null;
}
};
final List<Request> mRequests = new ArrayList<>();
public CallerInfoAsyncQueryFactoryFixture() throws Exception {
Log.i(this, "Creating ...");
}
@Override
public CallerInfoAsyncQueryFactory getTestDouble() {
return mCallerInfoAsyncQueryFactory;
}
}