1 /* 2 * Copyright (C) 2020 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 package com.android.settings.display; 17 18 import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE; 19 import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE; 20 21 import static com.google.common.truth.Truth.assertThat; 22 23 import static org.mockito.Mockito.spy; 24 import static org.mockito.Mockito.when; 25 26 import android.content.Context; 27 import android.location.LocationManager; 28 29 import org.junit.Before; 30 import org.junit.Test; 31 import org.junit.runner.RunWith; 32 import org.mockito.Mock; 33 import org.mockito.MockitoAnnotations; 34 import org.robolectric.RobolectricTestRunner; 35 import org.robolectric.RuntimeEnvironment; 36 37 @RunWith(RobolectricTestRunner.class) 38 public class TwilightLocationPreferenceControllerTest { 39 private static final String TEST_KEY = "test_key"; 40 41 private Context mContext; 42 private TwilightLocationPreferenceController mController; 43 44 @Mock 45 private LocationManager mLocationManager; 46 47 @Before setUp()48 public void setUp() { 49 MockitoAnnotations.initMocks(this); 50 mContext = spy(RuntimeEnvironment.application); 51 when(mContext.getSystemService(LocationManager.class)).thenReturn(mLocationManager); 52 mController = new TwilightLocationPreferenceController(mContext, TEST_KEY); 53 } 54 55 @Test getAvailabilityStatus_locationEnabled_shouldBeCONDITIONALLY_UNAVAILABLE()56 public void getAvailabilityStatus_locationEnabled_shouldBeCONDITIONALLY_UNAVAILABLE() { 57 when(mLocationManager.isLocationEnabled()).thenReturn(true); 58 59 assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE); 60 } 61 62 @Test getAvailabilityStatus_locationDisabled_shouldBeAVAILABLE_UNSEARCHABLE()63 public void getAvailabilityStatus_locationDisabled_shouldBeAVAILABLE_UNSEARCHABLE() { 64 when(mLocationManager.isLocationEnabled()).thenReturn(false); 65 66 assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE); 67 } 68 } 69