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.deviceinfo; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.content.DialogInterface; 22 import android.os.Bundle; 23 import android.os.storage.VolumeRecord; 24 import android.widget.Button; 25 26 import androidx.appcompat.app.AlertDialog; 27 import androidx.fragment.app.FragmentActivity; 28 29 import com.android.settings.R; 30 import com.android.settings.deviceinfo.PrivateVolumeForget.ForgetConfirmFragment; 31 import com.android.settings.testutils.shadow.ShadowStorageManager; 32 33 import org.junit.After; 34 import org.junit.Before; 35 import org.junit.Test; 36 import org.junit.runner.RunWith; 37 import org.robolectric.RobolectricTestRunner; 38 import org.robolectric.annotation.Config; 39 import org.robolectric.shadows.androidx.fragment.FragmentController; 40 41 @RunWith(RobolectricTestRunner.class) 42 @Config(shadows = ShadowStorageManager.class) 43 public class PrivateVolumeForgetTest { 44 45 private PrivateVolumeForget mFragment; 46 private FragmentActivity mActivity; 47 48 @Before setUp()49 public void setUp() { 50 final Bundle bundle = new Bundle(); 51 bundle.putString(VolumeRecord.EXTRA_FS_UUID, "id"); 52 mFragment = FragmentController.of(new PrivateVolumeForget(), bundle) 53 .create() 54 .start() 55 .resume() 56 .visible() 57 .get(); 58 mActivity = mFragment.getActivity(); 59 } 60 61 @After tearDown()62 public void tearDown() { 63 ShadowStorageManager.reset(); 64 } 65 66 @Test OnClickListener_shouldCallForget()67 public void OnClickListener_shouldCallForget() { 68 assertThat(ShadowStorageManager.isForgetCalled()).isFalse(); 69 70 final Button confirm = mFragment.getView().findViewById(R.id.confirm); 71 72 confirm.performClick(); 73 final ForgetConfirmFragment confirmFragment = 74 (ForgetConfirmFragment) mActivity.getSupportFragmentManager().findFragmentByTag( 75 PrivateVolumeForget.TAG_FORGET_CONFIRM); 76 77 assertThat(confirmFragment).isNotNull(); 78 79 final AlertDialog dialog = (AlertDialog) confirmFragment.getDialog(); 80 final Button forget = dialog.getButton(DialogInterface.BUTTON_POSITIVE); 81 82 forget.performClick(); 83 84 assertThat(ShadowStorageManager.isForgetCalled()).isTrue(); 85 } 86 }