1 /*
2  * Copyright (C) 2019 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.dashboard;
17 
18 import static com.android.settingslib.core.instrumentation.Instrumentable.METRICS_CATEGORY_UNKNOWN;
19 
20 import static com.google.common.truth.Truth.assertThat;
21 
22 import android.content.Context;
23 
24 import androidx.preference.PreferenceManager;
25 import androidx.preference.PreferenceScreen;
26 
27 import com.android.settings.core.BasePreferenceController;
28 
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.robolectric.RobolectricTestRunner;
33 import org.robolectric.RuntimeEnvironment;
34 
35 @RunWith(RobolectricTestRunner.class)
36 public class ControllerFutureTaskTest {
37     private static final String KEY = "my_key";
38 
39     private Context mContext;
40     private TestPreferenceController mTestController;
41     private PreferenceScreen mScreen;
42 
43     @Before
setUp()44     public void setUp() {
45         mContext = RuntimeEnvironment.application;
46         mTestController = new TestPreferenceController(mContext, KEY);
47         final PreferenceManager preferenceManager = new PreferenceManager(mContext);
48         mScreen = preferenceManager.createPreferenceScreen(mContext);
49     }
50 
51     @Test
getController_addTask_checkControllerKey()52     public void getController_addTask_checkControllerKey() {
53         final ControllerFutureTask futureTask = new ControllerFutureTask(
54                 new ControllerTask(mTestController, mScreen, null /* metricsFeature */,
55                         METRICS_CATEGORY_UNKNOWN), null /* result */);
56 
57         assertThat(futureTask.getController().getPreferenceKey()).isEqualTo(KEY);
58     }
59 
60 
61     static class TestPreferenceController extends BasePreferenceController {
TestPreferenceController(Context context, String preferenceKey)62         TestPreferenceController(Context context, String preferenceKey) {
63             super(context, preferenceKey);
64         }
65 
66         @Override
getAvailabilityStatus()67         public int getAvailabilityStatus() {
68             return AVAILABLE;
69         }
70     }
71 }
72