DirectToVoicemailCallFilterTest.java revision 67d34fa0524d10d5de190592c1f5f88c4dc31743
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 when(mCall.getHandle()).thenReturn(TEST_HANDLE); 46 } 47 48 @SmallTest 49 public void testSendToVoicemail() { 50 CallerInfoLookupHelper.OnQueryCompleteListener queryListener = verifyLookupStart(); 51 52 CallerInfo callerInfo = new CallerInfo(); 53 callerInfo.shouldSendToVoicemail = true; 54 55 queryListener.onCallerInfoQueryComplete(TEST_HANDLE, callerInfo); 56 verify(mCallback).onCallFilteringComplete(mCall, 57 new CallFilteringResult( 58 false, // shouldAllowCall 59 true, // shouldReject 60 true, // shouldAddToCallLog 61 true // shouldShowNotification 62 )); 63 } 64 65 @SmallTest 66 public void testDontSendToVoicemail() { 67 CallerInfoLookupHelper.OnQueryCompleteListener queryListener = verifyLookupStart(); 68 69 CallerInfo callerInfo = new CallerInfo(); 70 callerInfo.shouldSendToVoicemail = false; 71 72 queryListener.onCallerInfoQueryComplete(TEST_HANDLE, callerInfo); 73 verify(mCallback).onCallFilteringComplete(mCall, 74 new CallFilteringResult( 75 true, // shouldAllowCall 76 false, // shouldReject 77 true, // shouldAddToCallLog 78 true // shouldShowNotification 79 )); 80 } 81 82 private CallerInfoLookupHelper.OnQueryCompleteListener verifyLookupStart() { 83 DirectToVoicemailCallFilter filter = 84 new DirectToVoicemailCallFilter(mCallerInfoLookupHelper); 85 filter.startFilterLookup(mCall, mCallback); 86 ArgumentCaptor<CallerInfoLookupHelper.OnQueryCompleteListener> captor = 87 ArgumentCaptor.forClass(CallerInfoLookupHelper.OnQueryCompleteListener.class); 88 verify(mCallerInfoLookupHelper).startLookup(eq(TEST_HANDLE), captor.capture()); 89 return captor.getValue(); 90 } 91} 92