Loading tests/telephonytests/src/android/telephony/ims/ImsServiceTest.java +90 −8 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.telephony.ims.feature.ImsFeature; import android.test.suitebuilder.annotation.SmallTest; import android.util.SparseArray; import com.android.ims.ImsManager; import com.android.ims.internal.IImsFeatureStatusCallback; import com.android.ims.internal.IImsServiceController; Loading @@ -31,6 +32,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; Loading @@ -38,6 +40,7 @@ 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.assertNotNull; import static junit.framework.Assert.assertNull; import static junit.framework.Assert.fail; import static org.mockito.Matchers.any; Loading @@ -46,6 +49,7 @@ 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.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; Loading Loading @@ -84,15 +88,15 @@ public class ImsServiceTest { @SmallTest public void testCreateMMTelFeature() throws RemoteException { mTestImsServiceBinder.createImsFeature(TEST_SLOT_0, ImsFeature.MMTEL, mTestCallback); when(mTestImsService.mMockMMTelFeature.getFeatureState()).thenReturn( when(mTestImsService.mSpyMMTelFeature.getFeatureState()).thenReturn( ImsFeature.STATE_READY); SparseArray<ImsFeature> features = mTestImsService.getImsFeatureMap(TEST_SLOT_0); assertEquals(mTestImsService.mMockMMTelFeature, assertEquals(mTestImsService.mSpyMMTelFeature, mTestImsService.getImsFeatureFromType(features, ImsFeature.MMTEL)); // Verify that upon creating a feature, we assign the callback and get the set feature state // when querying it. verify(mTestImsService.mMockMMTelFeature).setImsFeatureStatusCallback(eq(mTestCallback)); verify(mTestImsService.mSpyMMTelFeature).setImsFeatureStatusCallback(eq(mTestCallback)); assertEquals(ImsFeature.STATE_READY, mTestImsServiceBinder.getFeatureStatus(TEST_SLOT_0, ImsFeature.MMTEL)); } Loading @@ -104,8 +108,8 @@ public class ImsServiceTest { mTestImsServiceBinder.removeImsFeature(TEST_SLOT_0, ImsFeature.MMTEL); verify(mTestImsService.mMockMMTelFeature).notifyFeatureRemoved(eq(0)); verify(mTestImsService.mMockMMTelFeature).setImsFeatureStatusCallback(null); verify(mTestImsService.mSpyMMTelFeature).notifyFeatureRemoved(eq(0)); verify(mTestImsService.mSpyMMTelFeature).setImsFeatureStatusCallback(null); SparseArray<ImsFeature> features = mTestImsService.getImsFeatureMap(TEST_SLOT_0); assertNull(mTestImsService.getImsFeatureFromType(features, ImsFeature.MMTEL)); } Loading @@ -118,7 +122,7 @@ public class ImsServiceTest { mTestImsServiceBinder.isConnected(TEST_SLOT_0, ImsFeature.MMTEL, 0 /*callSessionType*/, 0 /*callType*/); verify(mTestImsService.mMockMMTelFeature).isConnected(anyInt(), anyInt()); verify(mTestImsService.mSpyMMTelFeature).isConnected(anyInt(), anyInt()); } @Test Loading @@ -129,7 +133,7 @@ public class ImsServiceTest { mTestImsServiceBinder.isConnected(TEST_SLOT_1, ImsFeature.MMTEL, 0 /*callSessionType*/, 0 /*callType*/); verify(mTestImsService.mMockMMTelFeature, never()).isConnected(anyInt(), anyInt()); verify(mTestImsService.mSpyMMTelFeature, never()).isConnected(anyInt(), anyInt()); } @Test Loading Loading @@ -161,6 +165,84 @@ public class ImsServiceTest { // Expected } verify(mTestImsService.mMockMMTelFeature, never()).isConnected(anyInt(), anyInt()); verify(mTestImsService.mSpyMMTelFeature, never()).isConnected(anyInt(), anyInt()); } /** * Tests that the new ImsService still sends the IMS_SERVICE_UP broadcast when the feature is * set to ready. */ @Test @SmallTest public void testImsServiceUpSentCompat() throws RemoteException { mTestImsServiceBinder.createImsFeature(TEST_SLOT_0, ImsFeature.MMTEL, mTestCallback); mTestImsService.mSpyMMTelFeature.sendSetFeatureState(ImsFeature.STATE_READY); ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); verify(mMockContext, times(2)).sendBroadcast(intentCaptor.capture()); try { // IMS_SERVICE_DOWN is always sent when createImsFeature completes assertNotNull(intentCaptor.getAllValues().get(0)); verifyServiceDownSent(intentCaptor.getAllValues().get(0)); // Verify IMS_SERVICE_UP is sent assertNotNull(intentCaptor.getAllValues().get(1)); verifyServiceUpSent(intentCaptor.getAllValues().get(1)); } catch (IndexOutOfBoundsException e) { fail("Did not receive all intents"); } } /** * Tests that the new ImsService still sends the IMS_SERVICE_DOWN broadcast when the feature is * set to initializing. */ @Test @SmallTest public void testImsServiceDownSentCompatInitializing() throws RemoteException { mTestImsServiceBinder.createImsFeature(TEST_SLOT_0, ImsFeature.MMTEL, mTestCallback); mTestImsService.mSpyMMTelFeature.sendSetFeatureState(ImsFeature.STATE_INITIALIZING); ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); verify(mMockContext, times(2)).sendBroadcast(intentCaptor.capture()); try { // IMS_SERVICE_DOWN is always sent when createImsFeature completes. assertNotNull(intentCaptor.getAllValues().get(0)); verifyServiceDownSent(intentCaptor.getAllValues().get(0)); // IMS_SERVICE_DOWN is sent when the service is STATE_INITIALIZING. assertNotNull(intentCaptor.getAllValues().get(1)); verifyServiceDownSent(intentCaptor.getAllValues().get(1)); } catch (IndexOutOfBoundsException e) { fail("Did not receive all intents"); } } /** * Tests that the new ImsService still sends the IMS_SERVICE_DOWN broadcast when the feature is * set to not available. */ @Test @SmallTest public void testImsServiceDownSentCompatNotAvailable() throws RemoteException { mTestImsServiceBinder.createImsFeature(TEST_SLOT_0, ImsFeature.MMTEL, mTestCallback); // The ImsService will send the STATE_NOT_AVAILABLE status as soon as the feature is // created. ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); verify(mMockContext).sendBroadcast(intentCaptor.capture()); assertNotNull(intentCaptor.getValue()); verifyServiceDownSent(intentCaptor.getValue()); } private void verifyServiceDownSent(Intent testIntent) { assertEquals(ImsManager.ACTION_IMS_SERVICE_DOWN, testIntent.getAction()); assertEquals(TEST_SLOT_0, testIntent.getIntExtra(ImsManager.EXTRA_PHONE_ID, -1)); } private void verifyServiceUpSent(Intent testIntent) { assertEquals(ImsManager.ACTION_IMS_SERVICE_UP, testIntent.getAction()); assertEquals(TEST_SLOT_0, testIntent.getIntExtra(ImsManager.EXTRA_PHONE_ID, -1)); } } tests/telephonytests/src/android/telephony/ims/TestImsService.java +10 −5 Original line number Diff line number Diff line Loading @@ -20,8 +20,10 @@ import android.content.Context; import android.telephony.ims.feature.MMTelFeature; import android.telephony.ims.feature.RcsFeature; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.Spy; import static org.mockito.Mockito.spy; /** * Test ImsService used by mockito to verify functionality. Loading @@ -29,14 +31,17 @@ import org.mockito.MockitoAnnotations; public class TestImsService extends ImsService { public TestMMTelFeature mSpyMMTelFeature; private TestMMTelFeature mTestMMTelFeature; public TestImsService(Context context) { attachBaseContext(context); MockitoAnnotations.initMocks(this); // Must create real MMTelFeature to initialize ImsFeature objects. mTestMMTelFeature = new TestMMTelFeature(); mSpyMMTelFeature = spy(mTestMMTelFeature); } @Mock public TestMMTelFeature mMockMMTelFeature; @Override public MMTelFeature onCreateEmergencyMMTelImsFeature(int slotId) { return null; Loading @@ -44,7 +49,7 @@ public class TestImsService extends ImsService { @Override public MMTelFeature onCreateMMTelImsFeature(int slotId) { return mMockMMTelFeature; return mSpyMMTelFeature; } @Override Loading tests/telephonytests/src/android/telephony/ims/TestMMTelFeature.java +4 −0 Original line number Diff line number Diff line Loading @@ -28,4 +28,8 @@ public class TestMMTelFeature extends MMTelFeature { public void onFeatureRemoved() { } public void sendSetFeatureState(int state) { setFeatureState(state); } } Loading
tests/telephonytests/src/android/telephony/ims/ImsServiceTest.java +90 −8 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.telephony.ims.feature.ImsFeature; import android.test.suitebuilder.annotation.SmallTest; import android.util.SparseArray; import com.android.ims.ImsManager; import com.android.ims.internal.IImsFeatureStatusCallback; import com.android.ims.internal.IImsServiceController; Loading @@ -31,6 +32,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; Loading @@ -38,6 +40,7 @@ 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.assertNotNull; import static junit.framework.Assert.assertNull; import static junit.framework.Assert.fail; import static org.mockito.Matchers.any; Loading @@ -46,6 +49,7 @@ 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.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; Loading Loading @@ -84,15 +88,15 @@ public class ImsServiceTest { @SmallTest public void testCreateMMTelFeature() throws RemoteException { mTestImsServiceBinder.createImsFeature(TEST_SLOT_0, ImsFeature.MMTEL, mTestCallback); when(mTestImsService.mMockMMTelFeature.getFeatureState()).thenReturn( when(mTestImsService.mSpyMMTelFeature.getFeatureState()).thenReturn( ImsFeature.STATE_READY); SparseArray<ImsFeature> features = mTestImsService.getImsFeatureMap(TEST_SLOT_0); assertEquals(mTestImsService.mMockMMTelFeature, assertEquals(mTestImsService.mSpyMMTelFeature, mTestImsService.getImsFeatureFromType(features, ImsFeature.MMTEL)); // Verify that upon creating a feature, we assign the callback and get the set feature state // when querying it. verify(mTestImsService.mMockMMTelFeature).setImsFeatureStatusCallback(eq(mTestCallback)); verify(mTestImsService.mSpyMMTelFeature).setImsFeatureStatusCallback(eq(mTestCallback)); assertEquals(ImsFeature.STATE_READY, mTestImsServiceBinder.getFeatureStatus(TEST_SLOT_0, ImsFeature.MMTEL)); } Loading @@ -104,8 +108,8 @@ public class ImsServiceTest { mTestImsServiceBinder.removeImsFeature(TEST_SLOT_0, ImsFeature.MMTEL); verify(mTestImsService.mMockMMTelFeature).notifyFeatureRemoved(eq(0)); verify(mTestImsService.mMockMMTelFeature).setImsFeatureStatusCallback(null); verify(mTestImsService.mSpyMMTelFeature).notifyFeatureRemoved(eq(0)); verify(mTestImsService.mSpyMMTelFeature).setImsFeatureStatusCallback(null); SparseArray<ImsFeature> features = mTestImsService.getImsFeatureMap(TEST_SLOT_0); assertNull(mTestImsService.getImsFeatureFromType(features, ImsFeature.MMTEL)); } Loading @@ -118,7 +122,7 @@ public class ImsServiceTest { mTestImsServiceBinder.isConnected(TEST_SLOT_0, ImsFeature.MMTEL, 0 /*callSessionType*/, 0 /*callType*/); verify(mTestImsService.mMockMMTelFeature).isConnected(anyInt(), anyInt()); verify(mTestImsService.mSpyMMTelFeature).isConnected(anyInt(), anyInt()); } @Test Loading @@ -129,7 +133,7 @@ public class ImsServiceTest { mTestImsServiceBinder.isConnected(TEST_SLOT_1, ImsFeature.MMTEL, 0 /*callSessionType*/, 0 /*callType*/); verify(mTestImsService.mMockMMTelFeature, never()).isConnected(anyInt(), anyInt()); verify(mTestImsService.mSpyMMTelFeature, never()).isConnected(anyInt(), anyInt()); } @Test Loading Loading @@ -161,6 +165,84 @@ public class ImsServiceTest { // Expected } verify(mTestImsService.mMockMMTelFeature, never()).isConnected(anyInt(), anyInt()); verify(mTestImsService.mSpyMMTelFeature, never()).isConnected(anyInt(), anyInt()); } /** * Tests that the new ImsService still sends the IMS_SERVICE_UP broadcast when the feature is * set to ready. */ @Test @SmallTest public void testImsServiceUpSentCompat() throws RemoteException { mTestImsServiceBinder.createImsFeature(TEST_SLOT_0, ImsFeature.MMTEL, mTestCallback); mTestImsService.mSpyMMTelFeature.sendSetFeatureState(ImsFeature.STATE_READY); ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); verify(mMockContext, times(2)).sendBroadcast(intentCaptor.capture()); try { // IMS_SERVICE_DOWN is always sent when createImsFeature completes assertNotNull(intentCaptor.getAllValues().get(0)); verifyServiceDownSent(intentCaptor.getAllValues().get(0)); // Verify IMS_SERVICE_UP is sent assertNotNull(intentCaptor.getAllValues().get(1)); verifyServiceUpSent(intentCaptor.getAllValues().get(1)); } catch (IndexOutOfBoundsException e) { fail("Did not receive all intents"); } } /** * Tests that the new ImsService still sends the IMS_SERVICE_DOWN broadcast when the feature is * set to initializing. */ @Test @SmallTest public void testImsServiceDownSentCompatInitializing() throws RemoteException { mTestImsServiceBinder.createImsFeature(TEST_SLOT_0, ImsFeature.MMTEL, mTestCallback); mTestImsService.mSpyMMTelFeature.sendSetFeatureState(ImsFeature.STATE_INITIALIZING); ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); verify(mMockContext, times(2)).sendBroadcast(intentCaptor.capture()); try { // IMS_SERVICE_DOWN is always sent when createImsFeature completes. assertNotNull(intentCaptor.getAllValues().get(0)); verifyServiceDownSent(intentCaptor.getAllValues().get(0)); // IMS_SERVICE_DOWN is sent when the service is STATE_INITIALIZING. assertNotNull(intentCaptor.getAllValues().get(1)); verifyServiceDownSent(intentCaptor.getAllValues().get(1)); } catch (IndexOutOfBoundsException e) { fail("Did not receive all intents"); } } /** * Tests that the new ImsService still sends the IMS_SERVICE_DOWN broadcast when the feature is * set to not available. */ @Test @SmallTest public void testImsServiceDownSentCompatNotAvailable() throws RemoteException { mTestImsServiceBinder.createImsFeature(TEST_SLOT_0, ImsFeature.MMTEL, mTestCallback); // The ImsService will send the STATE_NOT_AVAILABLE status as soon as the feature is // created. ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); verify(mMockContext).sendBroadcast(intentCaptor.capture()); assertNotNull(intentCaptor.getValue()); verifyServiceDownSent(intentCaptor.getValue()); } private void verifyServiceDownSent(Intent testIntent) { assertEquals(ImsManager.ACTION_IMS_SERVICE_DOWN, testIntent.getAction()); assertEquals(TEST_SLOT_0, testIntent.getIntExtra(ImsManager.EXTRA_PHONE_ID, -1)); } private void verifyServiceUpSent(Intent testIntent) { assertEquals(ImsManager.ACTION_IMS_SERVICE_UP, testIntent.getAction()); assertEquals(TEST_SLOT_0, testIntent.getIntExtra(ImsManager.EXTRA_PHONE_ID, -1)); } }
tests/telephonytests/src/android/telephony/ims/TestImsService.java +10 −5 Original line number Diff line number Diff line Loading @@ -20,8 +20,10 @@ import android.content.Context; import android.telephony.ims.feature.MMTelFeature; import android.telephony.ims.feature.RcsFeature; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.Spy; import static org.mockito.Mockito.spy; /** * Test ImsService used by mockito to verify functionality. Loading @@ -29,14 +31,17 @@ import org.mockito.MockitoAnnotations; public class TestImsService extends ImsService { public TestMMTelFeature mSpyMMTelFeature; private TestMMTelFeature mTestMMTelFeature; public TestImsService(Context context) { attachBaseContext(context); MockitoAnnotations.initMocks(this); // Must create real MMTelFeature to initialize ImsFeature objects. mTestMMTelFeature = new TestMMTelFeature(); mSpyMMTelFeature = spy(mTestMMTelFeature); } @Mock public TestMMTelFeature mMockMMTelFeature; @Override public MMTelFeature onCreateEmergencyMMTelImsFeature(int slotId) { return null; Loading @@ -44,7 +49,7 @@ public class TestImsService extends ImsService { @Override public MMTelFeature onCreateMMTelImsFeature(int slotId) { return mMockMMTelFeature; return mSpyMMTelFeature; } @Override Loading
tests/telephonytests/src/android/telephony/ims/TestMMTelFeature.java +4 −0 Original line number Diff line number Diff line Loading @@ -28,4 +28,8 @@ public class TestMMTelFeature extends MMTelFeature { public void onFeatureRemoved() { } public void sendSetFeatureState(int state) { setFeatureState(state); } }