1 /* 2 * Copyright (C) 2017 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.development; 18 19 import static org.mockito.Mockito.spy; 20 import static org.mockito.Mockito.verify; 21 import static org.mockito.Mockito.when; 22 23 import android.content.Context; 24 import android.os.SystemProperties; 25 26 import androidx.lifecycle.LifecycleOwner; 27 import androidx.preference.ListPreference; 28 import androidx.preference.PreferenceScreen; 29 30 import com.android.settingslib.core.lifecycle.Lifecycle; 31 32 import org.junit.Before; 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.RobolectricTestRunner; 38 import org.robolectric.RuntimeEnvironment; 39 40 @RunWith(RobolectricTestRunner.class) 41 public class LogPersistPreferenceControllerTest { 42 43 @Mock 44 private ListPreference mPreference; 45 @Mock 46 private PreferenceScreen mScreen; 47 @Mock 48 private DevelopmentSettingsDashboardFragment mFragment; 49 50 private Context mContext; 51 private LogPersistPreferenceController mController; 52 private LifecycleOwner mLifecycleOwner; 53 private Lifecycle mLifecycle; 54 55 @Before setup()56 public void setup() { 57 MockitoAnnotations.initMocks(this); 58 mContext = RuntimeEnvironment.application; 59 mLifecycleOwner = () -> mLifecycle; 60 mLifecycle = new Lifecycle(mLifecycleOwner); 61 mController = spy(new LogPersistPreferenceController(mContext, mFragment, mLifecycle)); 62 when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); 63 SystemProperties.set("ro.debuggable", "1"); 64 mController.displayPreference(mScreen); 65 } 66 67 @Test onDeveloperOptionsSwitchDisabled_shouldResetLogOption()68 public void onDeveloperOptionsSwitchDisabled_shouldResetLogOption() { 69 mController.onDeveloperOptionsSwitchDisabled(); 70 71 verify(mController).writeLogpersistOption(null, true); 72 } 73 } 74