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