1 /*
2  * Copyright (C) 2018 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.homepage;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import static org.mockito.ArgumentMatchers.anyInt;
22 import static org.mockito.ArgumentMatchers.nullable;
23 import static org.mockito.Mockito.doReturn;
24 import static org.mockito.Mockito.spy;
25 import static org.mockito.Mockito.verify;
26 import static org.mockito.Mockito.when;
27 
28 import android.content.Context;
29 import android.graphics.drawable.Drawable;
30 import android.os.Bundle;
31 
32 import androidx.preference.Preference;
33 import androidx.preference.PreferenceScreen;
34 
35 import com.android.settings.R;
36 import com.android.settings.testutils.FakeFeatureFactory;
37 
38 import org.junit.Before;
39 import org.junit.Test;
40 import org.junit.runner.RunWith;
41 import org.robolectric.RobolectricTestRunner;
42 import org.robolectric.RuntimeEnvironment;
43 
44 @RunWith(RobolectricTestRunner.class)
45 public class TopLevelSettingsTest {
46     private Context mContext;
47     private TopLevelSettings mSettings;
48 
49     @Before
setUp()50     public void setUp() {
51         mContext = RuntimeEnvironment.application;
52         mSettings = spy(new TopLevelSettings());
53         when(mSettings.getContext()).thenReturn(mContext);
54         final FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest();
55         when(featureFactory.dashboardFeatureProvider
56                 .getTilesForCategory(nullable(String.class)))
57                 .thenReturn(null);
58         mSettings.onAttach(mContext);
59     }
60 
61     @Test
shouldForceRoundedIcon_true()62     public void shouldForceRoundedIcon_true() {
63         assertThat(mSettings.shouldForceRoundedIcon()).isTrue();
64     }
65 
66     @Test
onCreatePreferences_shouldTintPreferenceIcon()67     public void onCreatePreferences_shouldTintPreferenceIcon() {
68         final Preference preference = new Preference(mContext);
69         preference.setTitle(R.string.network_dashboard_title);
70         final Drawable icon = spy(mContext.getDrawable(R.drawable.ic_settings_wireless));
71         preference.setIcon(icon);
72         final PreferenceScreen screen = spy(new PreferenceScreen(mContext, null /* attrs */));
73         doReturn(1).when(screen).getPreferenceCount();
74         doReturn(preference).when(screen).getPreference(anyInt());
75         doReturn(screen).when(mSettings).getPreferenceScreen();
76         doReturn(0).when(mSettings).getPreferenceScreenResId();
77 
78         mSettings.onCreatePreferences(new Bundle(), "rootKey");
79 
80         verify(icon).setTint(anyInt());
81     }
82 }
83