DirectToVoicemailCallFilterTest.java revision f2373e177b6e122b84dd1a22320629d0280de1c6
1/* 2 * Copyright (C) 2016 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 android.net.Uri; 20import android.test.suitebuilder.annotation.SmallTest; 21 22import com.android.internal.telephony.CallerInfo; 23import com.android.server.telecom.Call; 24import com.android.server.telecom.callfiltering.CallFilterResultCallback; 25import com.android.server.telecom.CallerInfoLookupHelper; 26import com.android.server.telecom.callfiltering.CallFilteringResult; 27import com.android.server.telecom.callfiltering.DirectToVoicemailCallFilter; 28 29import org.mockito.ArgumentCaptor; 30import org.mockito.Mock; 31 32import static org.mockito.Matchers.eq; 33import static org.mockito.Mockito.verify; 34import static org.mockito.Mockito.when; 35 36public class DirectToVoicemailCallFilterTest extends TelecomTestCase { 37 @Mock private CallerInfoLookupHelper mCallerInfoLookupHelper; 38 @Mock private CallFilterResultCallback mCallback; 39 @Mock private Call mCall; 40 41 private static final Uri TEST_HANDLE = Uri.parse("tel:1235551234"); 42 43 public void setUp() throws Exception { 44 super.setUp(); 45 } 46 47 @SmallTest 48 public void testSendToVoicemail() { 49 CallerInfoLookupHelper.OnQueryCompleteListener queryListener = verifyLookupStart(); 50 51 CallerInfo callerInfo = new CallerInfo(); 52 callerInfo.shouldSendToVoicemail = true; 53 54 queryListener.onCallerInfoQueryComplete(TEST_HANDLE, callerInfo); 55 verify(mCallback).onCallFilteringComplete(mCall, 56 new CallFilteringResult( 57 false, // shouldAllowCall 58 true, // shouldReject 59 true, // shouldAddToCallLog 60 true // shouldShowNotification 61 )); 62 } 63 64 @SmallTest 65 public void testDontSendToVoicemail() { 66 CallerInfoLookupHelper.OnQueryCompleteListener queryListener = verifyLookupStart(); 67 68 CallerInfo callerInfo = new CallerInfo(); 69 callerInfo.shouldSendToVoicemail = false; 70 71 queryListener.onCallerInfoQueryComplete(TEST_HANDLE, callerInfo); 72 verify(mCallback).onCallFilteringComplete(mCall, 73 new CallFilteringResult( 74 true, // shouldAllowCall 75 false, // shouldReject 76 true, // shouldAddToCallLog 77 true // shouldShowNotification 78 )); 79 } 80 81 @SmallTest 82 public void testNullResponseFromLookupHelper() { 83 CallerInfoLookupHelper.OnQueryCompleteListener queryListener = verifyLookupStart(null); 84 85 queryListener.onCallerInfoQueryComplete(null, null); 86 verify(mCallback).onCallFilteringComplete(mCall, 87 new CallFilteringResult( 88 true, // shouldAllowCall 89 false, // shouldReject 90 true, // shouldAddToCallLog 91 true // shouldShowNotification 92 )); 93 } 94 95 private CallerInfoLookupHelper.OnQueryCompleteListener verifyLookupStart() { 96 return verifyLookupStart(TEST_HANDLE); 97 } 98 99 private CallerInfoLookupHelper.OnQueryCompleteListener verifyLookupStart(Uri handle) { 100 when(mCall.getHandle()).thenReturn(handle); 101 DirectToVoicemailCallFilter filter = 102 new DirectToVoicemailCallFilter(mCallerInfoLookupHelper); 103 filter.startFilterLookup(mCall, mCallback); 104 ArgumentCaptor<CallerInfoLookupHelper.OnQueryCompleteListener> captor = 105 ArgumentCaptor.forClass(CallerInfoLookupHelper.OnQueryCompleteListener.class); 106 verify(mCallerInfoLookupHelper).startLookup(eq(handle), captor.capture()); 107 return captor.getValue(); 108 } 109} 110