diff options
author | Kai Shi <kaishi@google.com> | 2019-03-19 23:18:34 -0700 |
---|---|---|
committer | Kai Shi <kaishi@google.com> | 2019-03-20 14:56:00 -0700 |
commit | 8c00b416b3590e861d158145a8e8d068506a6176 (patch) | |
tree | 0f59b3deb3a619319d0b2b1d0f81383bc1bf2171 /tests/wifitests/src/com/android/server/wifi/CellularLinkLayerStatsCollectorTest.java | |
parent | e724fca826060a9394e6ebce182348034d99f343 (diff) | |
download | android_frameworks_opt_net_wifi-8c00b416b3590e861d158145a8e8d068506a6176.tar.gz android_frameworks_opt_net_wifi-8c00b416b3590e861d158145a8e8d068506a6176.tar.bz2 android_frameworks_opt_net_wifi-8c00b416b3590e861d158145a8e8d068506a6176.zip |
WiFi unit test: mock static methods of SubscriptionManager properly.
The following static methods are mocked by using ExtendedMockito:
SubscriptionManager.getDefaultDataSubscriptionId()
SubscriptionManager.getDefaultSubscriptionId()
Bug: 128966900
Bug: 128949241
Test: Unit tests for Wifi: frameworks/opt/net/wifi/tests/wifitests/runtest.sh
Change-Id: I88bf7fdf86eb9d49e03c33404b0e8e958ecf0b38
Diffstat (limited to 'tests/wifitests/src/com/android/server/wifi/CellularLinkLayerStatsCollectorTest.java')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/CellularLinkLayerStatsCollectorTest.java | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/CellularLinkLayerStatsCollectorTest.java b/tests/wifitests/src/com/android/server/wifi/CellularLinkLayerStatsCollectorTest.java index 513b30870..8b1647fcb 100644 --- a/tests/wifitests/src/com/android/server/wifi/CellularLinkLayerStatsCollectorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/CellularLinkLayerStatsCollectorTest.java @@ -25,10 +25,12 @@ import static android.telephony.TelephonyManager.NETWORK_TYPE_TD_SCDMA; import static android.telephony.TelephonyManager.NETWORK_TYPE_UMTS; import static android.telephony.TelephonyManager.NETWORK_TYPE_UNKNOWN; +import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession; +import static com.android.dx.mockito.inline.extended.ExtendedMockito.when; + import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.validateMockitoUsage; -import static org.mockito.Mockito.when; import android.content.Context; import android.telephony.CellInfo; @@ -55,6 +57,7 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.mockito.MockitoSession; import java.util.ArrayList; import java.util.List; @@ -69,6 +72,8 @@ public class CellularLinkLayerStatsCollectorTest { private static final int DBM_VAL = -110; private static final int DB_VAL = -20; private static final int DB_VAL_EVDO = 4; + private static final int SUBID = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID; + MockitoSession mMockingSession = null; @Mock Context mContext; @Mock TelephonyManager mTelephonyManager; @Mock SubscriptionManager mSubscriptionManager; @@ -83,11 +88,17 @@ public class CellularLinkLayerStatsCollectorTest { when(mTelephonyManager.createForSubscriptionId(anyInt())) .thenReturn(mTelephonyManager); mCollector = new CellularLinkLayerStatsCollector(mContext); + mMockingSession = mockitoSession().mockStatic(SubscriptionManager.class).startMocking(); + when(SubscriptionManager.getDefaultDataSubscriptionId()).thenReturn(SUBID); + when(SubscriptionManager.getDefaultSubscriptionId()).thenReturn(SUBID); } @After public void cleanUp() throws Exception { validateMockitoUsage(); + if (mMockingSession != null) { + mMockingSession.finishMocking(); + } } private List<CellInfo> generateCellInfoList(@NetworkType int networkType) { @@ -173,6 +184,9 @@ public class CellularLinkLayerStatsCollectorTest { CellularLinkLayerStats mStats = mCollector.update(); + assertEquals(SUBID, SubscriptionManager.getDefaultDataSubscriptionId()); + assertEquals(SUBID, SubscriptionManager.getDefaultSubscriptionId()); + assertEquals(trueStats.getSignalStrengthDbm(), mStats.getSignalStrengthDbm()); assertEquals(trueStats.getSignalStrengthDb(), mStats.getSignalStrengthDb()); assertEquals(trueStats.getDataNetworkType(), mStats.getDataNetworkType()); @@ -180,7 +194,7 @@ public class CellularLinkLayerStatsCollectorTest { } @Test - public void testEmptySignalStrength() throws Exception { + public void testEmptySignalStrengthLte() throws Exception { @NetworkType int networkType; CellularLinkLayerStats trueStats = new CellularLinkLayerStats(); |