Home | History | Annotate | Download | only in development
      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.arch.lifecycle.LifecycleOwner;
     24 import android.content.Context;
     25 import android.os.SystemProperties;
     26 import android.support.v7.preference.ListPreference;
     27 import android.support.v7.preference.PreferenceScreen;
     28 
     29 import com.android.settings.testutils.SettingsRobolectricTestRunner;
     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.RuntimeEnvironment;
     38 
     39 @RunWith(SettingsRobolectricTestRunner.class)
     40 public class LogPersistPreferenceControllerTest {
     41 
     42     @Mock
     43     private ListPreference mPreference;
     44     @Mock
     45     private PreferenceScreen mScreen;
     46     @Mock
     47     private DevelopmentSettingsDashboardFragment mFragment;
     48 
     49     private Context mContext;
     50     private LogPersistPreferenceController mController;
     51     private LifecycleOwner mLifecycleOwner;
     52     private Lifecycle mLifecycle;
     53 
     54     @Before
     55     public void setup() {
     56         MockitoAnnotations.initMocks(this);
     57         mContext = RuntimeEnvironment.application;
     58         mLifecycleOwner = () -> mLifecycle;
     59         mLifecycle = new Lifecycle(mLifecycleOwner);
     60         mController = spy(new LogPersistPreferenceController(mContext, mFragment, mLifecycle));
     61         when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
     62         SystemProperties.set("ro.debuggable", "1");
     63         mController.displayPreference(mScreen);
     64     }
     65 
     66     @Test
     67     public void onDeveloperOptionsSwitchDisabled_shouldResetLogOption() {
     68         mController.onDeveloperOptionsSwitchDisabled();
     69 
     70         verify(mController).writeLogpersistOption(null, true);
     71     }
     72 }
     73