1/* 2 * Copyright (C) 2017 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 17package com.android.systemui.qs; 18 19 20import static org.junit.Assert.assertTrue; 21 22import static org.mockito.ArgumentMatchers.any; 23import static org.mockito.Mockito.atLeastOnce; 24import static org.mockito.Mockito.mock; 25import static org.mockito.Mockito.never; 26import static org.mockito.Mockito.verify; 27 28import android.content.Context; 29import android.content.res.ColorStateList; 30import android.graphics.drawable.Drawable; 31import android.test.suitebuilder.annotation.SmallTest; 32import com.android.systemui.SysuiTestCase; 33import com.android.systemui.qs.AlphaControlledSignalTileView.AlphaControlledSlashDrawable; 34import com.android.systemui.qs.AlphaControlledSignalTileView.AlphaControlledSlashImageView; 35import org.junit.Test; 36 37@SmallTest 38public class AlphaControlledSignalTileViewTest extends SysuiTestCase { 39 40 private AlphaControlledSignalTileView mTileView; 41 42 @Test 43 public void testTileView_createsAlphaControlledSlashImageView() { 44 mTileView = new AlphaControlledSignalTileView(mContext); 45 46 assertTrue(mTileView.createSlashImageView(mContext) 47 instanceof AlphaControlledSlashImageView); 48 } 49 50 /// AlphaControlledSlashImageView tests 51 @Test 52 public void testSlashImageView_createsAlphaControlledSlashDrawable() { 53 TestableSlashImageView iv = new TestableSlashImageView(mContext); 54 55 iv.ensureSlashDrawable(); 56 assertTrue(iv.getSlashDrawable() instanceof AlphaControlledSlashDrawable); 57 } 58 59 /// AlphaControlledSlashDrawable tests 60 @Test 61 public void testSlashDrawable_doesNotSetTintList() { 62 Drawable mockDrawable = mock(Drawable.class); 63 AlphaControlledSlashDrawable drawable = new AlphaControlledSlashDrawable(mockDrawable); 64 ColorStateList list = ColorStateList.valueOf(0xffffff); 65 drawable.setTintList(list); 66 verify(mockDrawable, never()).setTintList(any()); 67 } 68 69 @Test 70 public void testSlashDrawable_setsFinalTintList() { 71 Drawable mockDrawable = mock(Drawable.class); 72 AlphaControlledSlashDrawable drawable = new AlphaControlledSlashDrawable(mockDrawable); 73 ColorStateList list = ColorStateList.valueOf(0xffffff); 74 drawable.setFinalTintList(list); 75 verify(mockDrawable, atLeastOnce()).setTintList(list); 76 } 77 78 // Expose getSlashDrawable 79 private static class TestableSlashImageView extends AlphaControlledSlashImageView { 80 TestableSlashImageView(Context c) { 81 super(c); 82 } 83 84 private SlashDrawable getSlashDrawable() { 85 return mSlash; 86 } 87 88 @Override 89 protected void setSlash(SlashDrawable slash) { 90 super.setSlash(slash); 91 } 92 } 93} 94