1 /* 2 * Copyright (C) 2018 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 17 package com.android.settings; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.view.LayoutInflater; 22 import android.widget.TextView; 23 24 import androidx.fragment.app.FragmentActivity; 25 26 import com.android.settings.testutils.shadow.ShadowBluetoothAdapter; 27 import com.android.settings.testutils.shadow.ShadowRecoverySystem; 28 import com.android.settings.testutils.shadow.ShadowWifiP2pManager; 29 30 import org.junit.After; 31 import org.junit.Before; 32 import org.junit.Ignore; 33 import org.junit.Test; 34 import org.junit.runner.RunWith; 35 import org.mockito.Mock; 36 import org.mockito.MockitoAnnotations; 37 import org.robolectric.Robolectric; 38 import org.robolectric.RobolectricTestRunner; 39 import org.robolectric.annotation.Config; 40 41 @RunWith(RobolectricTestRunner.class) 42 @Config(shadows = {ShadowRecoverySystem.class, 43 ShadowWifiP2pManager.class, ShadowBluetoothAdapter.class 44 }) 45 public class ResetNetworkConfirmTest { 46 47 private FragmentActivity mActivity; 48 @Mock 49 private ResetNetworkConfirm mResetNetworkConfirm; 50 51 @Before setUp()52 public void setUp() { 53 MockitoAnnotations.initMocks(this); 54 mResetNetworkConfirm = new ResetNetworkConfirm(); 55 mActivity = Robolectric.setupActivity(FragmentActivity.class); 56 mResetNetworkConfirm.mActivity = mActivity; 57 } 58 59 @After tearDown()60 public void tearDown() { 61 ShadowRecoverySystem.reset(); 62 ShadowWifiP2pManager.reset(); 63 } 64 65 @Test 66 @Ignore testResetNetworkData_resetEsim()67 public void testResetNetworkData_resetEsim() { 68 mResetNetworkConfirm.mEraseEsim = true; 69 70 mResetNetworkConfirm.mFinalClickListener.onClick(null /* View */); 71 Robolectric.getBackgroundThreadScheduler().advanceToLastPostedRunnable(); 72 73 assertThat(ShadowRecoverySystem.getWipeEuiccCalledCount()).isEqualTo(1); 74 } 75 76 @Test 77 @Ignore testResetNetworkData_notResetEsim()78 public void testResetNetworkData_notResetEsim() { 79 mResetNetworkConfirm.mEraseEsim = false; 80 81 mResetNetworkConfirm.mFinalClickListener.onClick(null /* View */); 82 Robolectric.getBackgroundThreadScheduler().advanceToLastPostedRunnable(); 83 84 assertThat(ShadowRecoverySystem.getWipeEuiccCalledCount()).isEqualTo(0); 85 } 86 87 /** 88 * Test for WifiP2pManager factoryReset method. 89 */ 90 @Test testResetNetworkData_resetP2p()91 public void testResetNetworkData_resetP2p() { 92 mResetNetworkConfirm.p2pFactoryReset(mActivity); 93 94 assertThat(ShadowWifiP2pManager.getFactoryResetCount()).isEqualTo(1); 95 } 96 97 @Test setSubtitle_eraseEsim()98 public void setSubtitle_eraseEsim() { 99 mResetNetworkConfirm.mEraseEsim = true; 100 mResetNetworkConfirm.mContentView = 101 LayoutInflater.from(mActivity).inflate(R.layout.reset_network_confirm, null); 102 103 mResetNetworkConfirm.setSubtitle(); 104 105 assertThat(((TextView) mResetNetworkConfirm.mContentView 106 .findViewById(R.id.reset_network_confirm)).getText()) 107 .isEqualTo(mActivity.getString(R.string.reset_network_final_desc_esim)); 108 } 109 110 @Test setSubtitle_notEraseEsim()111 public void setSubtitle_notEraseEsim() { 112 mResetNetworkConfirm.mEraseEsim = false; 113 mResetNetworkConfirm.mContentView = 114 LayoutInflater.from(mActivity).inflate(R.layout.reset_network_confirm, null); 115 116 mResetNetworkConfirm.setSubtitle(); 117 118 assertThat(((TextView) mResetNetworkConfirm.mContentView 119 .findViewById(R.id.reset_network_confirm)).getText()) 120 .isEqualTo(mActivity.getString(R.string.reset_network_final_desc)); 121 } 122 } 123