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 import static org.mockito.Mockito.spy; 21 22 import android.app.Activity; 23 24 import com.android.settings.testutils.SettingsRobolectricTestRunner; 25 import com.android.settings.testutils.shadow.ShadowRecoverySystem; 26 27 import org.junit.After; 28 import org.junit.Before; 29 import org.junit.Test; 30 import org.junit.runner.RunWith; 31 import org.mockito.Mock; 32 import org.mockito.MockitoAnnotations; 33 import org.robolectric.Robolectric; 34 import org.robolectric.annotation.Config; 35 36 @RunWith(SettingsRobolectricTestRunner.class) 37 @Config(shadows = {ShadowRecoverySystem.class}) 38 public class ResetNetworkConfirmTest { 39 40 private Activity mActivity; 41 @Mock 42 private ResetNetworkConfirm mResetNetworkConfirm; 43 44 @Before setUp()45 public void setUp() { 46 MockitoAnnotations.initMocks(this); 47 mResetNetworkConfirm = spy(new ResetNetworkConfirm()); 48 mActivity = Robolectric.setupActivity(Activity.class); 49 } 50 51 @After tearDown()52 public void tearDown() { 53 ShadowRecoverySystem.reset(); 54 } 55 56 @Test testResetNetworkData_resetEsim()57 public void testResetNetworkData_resetEsim() { 58 mResetNetworkConfirm.mEraseEsim = true; 59 60 mResetNetworkConfirm.esimFactoryReset(mActivity, "" /* packageName */); 61 Robolectric.getBackgroundThreadScheduler().advanceToLastPostedRunnable(); 62 63 assertThat(mResetNetworkConfirm.mEraseEsimTask).isNotNull(); 64 assertThat(ShadowRecoverySystem.getWipeEuiccCalledCount()) 65 .isEqualTo(1); 66 } 67 68 @Test testResetNetworkData_notResetEsim()69 public void testResetNetworkData_notResetEsim() { 70 mResetNetworkConfirm.mEraseEsim = false; 71 72 mResetNetworkConfirm.esimFactoryReset(mActivity, "" /* packageName */); 73 74 assertThat(mResetNetworkConfirm.mEraseEsimTask).isNull(); 75 assertThat(ShadowRecoverySystem.getWipeEuiccCalledCount()) 76 .isEqualTo(0); 77 } 78 } 79