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.dashboard; 18 19 import static com.google.common.truth.Truth.assertThat; 20 import static org.mockito.Mockito.mock; 21 import static org.mockito.Mockito.spy; 22 import static org.mockito.Mockito.verify; 23 import static org.mockito.Mockito.when; 24 25 import android.content.Context; 26 import android.graphics.Color; 27 import android.graphics.PorterDuff; 28 import android.graphics.drawable.ColorDrawable; 29 import android.graphics.drawable.ShapeDrawable; 30 31 import com.android.settings.R; 32 import com.android.settings.testutils.SettingsRobolectricTestRunner; 33 34 import org.junit.Before; 35 import org.junit.Test; 36 import org.junit.runner.RunWith; 37 import org.robolectric.RuntimeEnvironment; 38 39 @RunWith(SettingsRobolectricTestRunner.class) 40 public class RoundedHomepageIconTest { 41 42 private Context mContext; 43 44 @Before setUp()45 public void setUp() { 46 mContext = RuntimeEnvironment.application; 47 } 48 49 @Test createIcon_shouldSetBackgroundAndInset()50 public void createIcon_shouldSetBackgroundAndInset() { 51 final RoundedHomepageIcon icon = 52 new RoundedHomepageIcon(mContext, new ColorDrawable(Color.BLACK)); 53 54 assertThat(icon.getNumberOfLayers()).isEqualTo(2); 55 assertThat(icon.getDrawable(0)) 56 .isEqualTo(mContext.getDrawable(R.drawable.ic_homepage_generic_background)); 57 } 58 59 @Test setBackgroundColor_shouldUpdateColorFilter()60 public void setBackgroundColor_shouldUpdateColorFilter() { 61 final RoundedHomepageIcon icon = 62 spy(new RoundedHomepageIcon(mContext, new ColorDrawable(Color.BLACK))); 63 final ShapeDrawable background = mock(ShapeDrawable.class); 64 when(icon.getDrawable(0)).thenReturn(background); 65 66 icon.setBackgroundColor(Color.BLUE); 67 68 verify(background).setColorFilter(Color.BLUE, PorterDuff.Mode.SRC_ATOP); 69 } 70 } 71