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