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 
17 package com.android.systemui.qs;
18 
19 
20 import static org.junit.Assert.assertTrue;
21 
22 import static org.mockito.ArgumentMatchers.any;
23 import static org.mockito.Mockito.atLeastOnce;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.never;
26 import static org.mockito.Mockito.verify;
27 
28 import android.content.Context;
29 import android.content.res.ColorStateList;
30 import android.graphics.drawable.Drawable;
31 import android.test.suitebuilder.annotation.SmallTest;
32 import com.android.systemui.SysuiTestCase;
33 import com.android.systemui.qs.AlphaControlledSignalTileView.AlphaControlledSlashDrawable;
34 import com.android.systemui.qs.AlphaControlledSignalTileView.AlphaControlledSlashImageView;
35 import org.junit.Test;
36 
37 @SmallTest
38 public class AlphaControlledSignalTileViewTest extends SysuiTestCase {
39 
40     private AlphaControlledSignalTileView mTileView;
41 
42     @Test
testTileView_createsAlphaControlledSlashImageView()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
testSlashImageView_createsAlphaControlledSlashDrawable()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
testSlashDrawable_doesNotSetTintList()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
testSlashDrawable_setsFinalTintList()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 {
TestableSlashImageView(Context c)80         TestableSlashImageView(Context c) {
81             super(c);
82         }
83 
getSlashDrawable()84         private SlashDrawable getSlashDrawable() {
85             return mSlash;
86         }
87 
88         @Override
setSlash(SlashDrawable slash)89         protected void setSlash(SlashDrawable slash) {
90             super.setSlash(slash);
91         }
92     }
93 }
94