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.internal.telephony; 18 19import android.content.Context; 20import android.telephony.TelephonyManager; 21import android.telephony.VisualVoicemailSmsFilterSettings; 22 23import junit.framework.TestCase; 24 25import org.mockito.Mockito; 26 27public class VisualVoicemailSmsFilterTest extends TestCase { 28 29 /** 30 * b/29123941 iPhone style notification SMS is neither 3GPP nor 3GPP2, but some plain text 31 * message. {@link android.telephony.SmsMessage.createFromPdu()} will fail to parse it and 32 * return an invalid object, causing {@link NullPointerException} on any operation if not 33 * handled. 34 */ 35 public void testUnsupportedPdu() { 36 Context context = Mockito.mock(Context.class); 37 TelephonyManager telephonyManager = Mockito.mock(TelephonyManager.class); 38 Mockito.when(context.getSystemServiceName(TelephonyManager.class)) 39 .thenReturn(Context.TELEPHONY_SERVICE); 40 Mockito.when(context.getSystemService(Mockito.anyString())).thenReturn(telephonyManager); 41 42 VisualVoicemailSmsFilterSettings settings = new VisualVoicemailSmsFilterSettings.Builder() 43 .build(); 44 45 Mockito.when(telephonyManager 46 .getVisualVoicemailSmsFilterSettings(Mockito.anyString(), Mockito.anyInt())) 47 .thenReturn(settings); 48 49 byte[][] pdus = { 50 ("MBOXUPDATE?m=11;server=example.com;" 51 + "port=143;name=1234567890@example.com;pw=CphQJKnYS4jEiDO").getBytes()}; 52 VisualVoicemailSmsFilter.filter(context, pdus, SmsConstants.FORMAT_3GPP2, 0, 0); 53 } 54 55} 56