• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.location
17 
18 import android.content.Context
19 import android.content.ContextWrapper
20 import android.location.LocationManager
21 import androidx.test.ext.junit.runners.AndroidJUnit4
22 import com.android.settings.R
23 import com.android.settings.flags.Flags
24 import com.android.settingslib.preference.CatalystScreenTestCase
25 import com.google.common.truth.Truth.assertThat
26 import org.junit.Test
27 import org.junit.runner.RunWith
28 import org.mockito.kotlin.doReturn
29 import org.mockito.kotlin.mock
30 import org.mockito.kotlin.stub
31 
32 @RunWith(AndroidJUnit4::class)
33 class LocationScreenTest : CatalystScreenTestCase() {
34     override val preferenceScreenCreator = LocationScreen()
35 
36     override val flagName: String
37         get() = Flags.FLAG_CATALYST_LOCATION_SETTINGS
38 
39     private val mockLocationManager = mock<LocationManager>()
40 
41     private val context =
42             object : ContextWrapper(appContext) {
getSystemServicenull43                 override fun getSystemService(name: String): Any =
44                     when (name) {
45                         Context.LOCATION_SERVICE -> mockLocationManager
46                         else -> super.getSystemService(name)
47                     }
48             }
49 
50     @Test
keynull51     fun key() {
52         assertThat(preferenceScreenCreator.key).isEqualTo(LocationScreen.KEY)
53     }
54 
55     @Test
getSummary_enableLocation_shouldReturnLoadingnull56     fun getSummary_enableLocation_shouldReturnLoading() {
57         mockLocationManager.stub { on { isLocationEnabled } doReturn true }
58 
59         assertThat(preferenceScreenCreator.getSummary(context)).isEqualTo(
60                 context.getString(R.string.location_settings_loading_app_permission_stats))
61     }
62 
63     @Test
getSummary_disableLocation_shouldReturnLocationOffnull64     fun getSummary_disableLocation_shouldReturnLocationOff() {
65         mockLocationManager.stub { on { isLocationEnabled } doReturn false }
66 
67         assertThat(preferenceScreenCreator.getSummary(context)).isEqualTo(
68                 context.getString(R.string.location_settings_summary_location_off))
69     }
70 
migrationnull71     override fun migration() {
72     }
73 }
74