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.PreferenceManager; 34 import androidx.preference.PreferenceScreen; 35 36 import com.android.settings.R; 37 import com.android.settings.testutils.FakeFeatureFactory; 38 39 import org.junit.Before; 40 import org.junit.Test; 41 import org.junit.runner.RunWith; 42 import org.robolectric.RobolectricTestRunner; 43 import org.robolectric.RuntimeEnvironment; 44 45 @RunWith(RobolectricTestRunner.class) 46 public class TopLevelSettingsTest { 47 private Context mContext; 48 private TopLevelSettings mSettings; 49 50 @Before setUp()51 public void setUp() { 52 mContext = RuntimeEnvironment.application; 53 mSettings = spy(new TopLevelSettings()); 54 when(mSettings.getContext()).thenReturn(mContext); 55 final FakeFeatureFactory featureFactory = FakeFeatureFactory.setupForTest(); 56 when(featureFactory.dashboardFeatureProvider 57 .getTilesForCategory(nullable(String.class))) 58 .thenReturn(null); 59 mSettings.onAttach(mContext); 60 } 61 62 @Test shouldForceRoundedIcon_true()63 public void shouldForceRoundedIcon_true() { 64 assertThat(mSettings.shouldForceRoundedIcon()).isTrue(); 65 } 66 67 @Test 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