如何使用Mockito或Roboelectric编写以下代码的测试

时间:2019-08-21 16:25:18

标签: android unit-testing mockito

我想使用模拟或机器人测试框架为以下代码编写单元测试。

 public static Boolean verifyNetworkAboveLollipop(Context context) {
        SubscriptionManager subscriptionManager = (SubscriptionManager) context.
                getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
        if (null != subscriptionManager) {
            @SuppressLint("MissingPermission") List<SubscriptionInfo> subscriptionInfoList = subscriptionManager.getActiveSubscriptionInfoList();
            if (null != subscriptionInfoList && 0 < subscriptionInfoList.size()) {
                for (SubscriptionInfo info : subscriptionInfoList) {
                    if (null != info && !TextUtils.isEmpty(info.getCarrierName())) {
                        String carrierName = info.getCarrierName().toString();
                        if ("Airtel".equalsIgnoreCase(carrierName)) {
                            return true;
                        }
                    }
                }
            }
        }
        return false;
    }

0 个答案:

没有答案