Loading tests/telephonytests/src/android/telephony/ims/ImsServiceTest.java +42 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.telephony.ims; import android.content.Context; import android.content.Intent; import android.os.RemoteException; import android.support.test.runner.AndroidJUnit4; Loading @@ -33,11 +34,17 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import static android.Manifest.permission.MODIFY_PHONE_STATE; import static android.Manifest.permission.READ_PHONE_STATE; import static com.android.internal.telephony.ims.ImsResolver.SERVICE_INTERFACE; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNull; import static junit.framework.Assert.fail; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; Loading @@ -54,13 +61,15 @@ public class ImsServiceTest { private TestImsService mTestImsService; private IImsServiceController mTestImsServiceBinder; @Mock private Context mMockContext; @Mock private IImsFeatureStatusCallback mTestCallback; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); mTestImsService = new TestImsService(); mTestImsService = new TestImsService(mMockContext); mTestImsServiceBinder = (IImsServiceController) mTestImsService.onBind( new Intent(SERVICE_INTERFACE)); } Loading Loading @@ -122,4 +131,36 @@ public class ImsServiceTest { verify(mTestImsService.mMockMMTelFeature, never()).isConnected(anyInt(), anyInt()); } @Test @SmallTest public void testCreateFeatureWithNoPermissions() throws RemoteException { doThrow(new SecurityException()).when(mMockContext).enforceCallingOrSelfPermission( eq(MODIFY_PHONE_STATE), anyString()); try { mTestImsServiceBinder.createImsFeature(TEST_SLOT_0, ImsFeature.MMTEL, mTestCallback); fail(); } catch (SecurityException e) { // Expected } } @Test @SmallTest public void testMethodWithNoPermissions() throws RemoteException { doThrow(new SecurityException()).when(mMockContext).enforceCallingOrSelfPermission( eq(READ_PHONE_STATE), anyString()); mTestImsServiceBinder.createImsFeature(TEST_SLOT_0, ImsFeature.MMTEL, mTestCallback); try { mTestImsServiceBinder.isConnected(TEST_SLOT_1, ImsFeature.MMTEL, 0 /*callSessionType*/, 0 /*callType*/); fail(); } catch (SecurityException e) { // Expected } verify(mTestImsService.mMockMMTelFeature, never()).isConnected(anyInt(), anyInt()); } } tests/telephonytests/src/android/telephony/ims/TestImsService.java +3 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.telephony.ims; import android.content.Context; import android.telephony.ims.feature.MMTelFeature; import android.telephony.ims.feature.RcsFeature; Loading @@ -28,7 +29,8 @@ import org.mockito.MockitoAnnotations; public class TestImsService extends ImsService { public TestImsService() { public TestImsService(Context context) { attachBaseContext(context); MockitoAnnotations.initMocks(this); } Loading Loading
tests/telephonytests/src/android/telephony/ims/ImsServiceTest.java +42 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.telephony.ims; import android.content.Context; import android.content.Intent; import android.os.RemoteException; import android.support.test.runner.AndroidJUnit4; Loading @@ -33,11 +34,17 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import static android.Manifest.permission.MODIFY_PHONE_STATE; import static android.Manifest.permission.READ_PHONE_STATE; import static com.android.internal.telephony.ims.ImsResolver.SERVICE_INTERFACE; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNull; import static junit.framework.Assert.fail; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; Loading @@ -54,13 +61,15 @@ public class ImsServiceTest { private TestImsService mTestImsService; private IImsServiceController mTestImsServiceBinder; @Mock private Context mMockContext; @Mock private IImsFeatureStatusCallback mTestCallback; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); mTestImsService = new TestImsService(); mTestImsService = new TestImsService(mMockContext); mTestImsServiceBinder = (IImsServiceController) mTestImsService.onBind( new Intent(SERVICE_INTERFACE)); } Loading Loading @@ -122,4 +131,36 @@ public class ImsServiceTest { verify(mTestImsService.mMockMMTelFeature, never()).isConnected(anyInt(), anyInt()); } @Test @SmallTest public void testCreateFeatureWithNoPermissions() throws RemoteException { doThrow(new SecurityException()).when(mMockContext).enforceCallingOrSelfPermission( eq(MODIFY_PHONE_STATE), anyString()); try { mTestImsServiceBinder.createImsFeature(TEST_SLOT_0, ImsFeature.MMTEL, mTestCallback); fail(); } catch (SecurityException e) { // Expected } } @Test @SmallTest public void testMethodWithNoPermissions() throws RemoteException { doThrow(new SecurityException()).when(mMockContext).enforceCallingOrSelfPermission( eq(READ_PHONE_STATE), anyString()); mTestImsServiceBinder.createImsFeature(TEST_SLOT_0, ImsFeature.MMTEL, mTestCallback); try { mTestImsServiceBinder.isConnected(TEST_SLOT_1, ImsFeature.MMTEL, 0 /*callSessionType*/, 0 /*callType*/); fail(); } catch (SecurityException e) { // Expected } verify(mTestImsService.mMockMMTelFeature, never()).isConnected(anyInt(), anyInt()); } }
tests/telephonytests/src/android/telephony/ims/TestImsService.java +3 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.telephony.ims; import android.content.Context; import android.telephony.ims.feature.MMTelFeature; import android.telephony.ims.feature.RcsFeature; Loading @@ -28,7 +29,8 @@ import org.mockito.MockitoAnnotations; public class TestImsService extends ImsService { public TestImsService() { public TestImsService(Context context) { attachBaseContext(context); MockitoAnnotations.initMocks(this); } Loading