• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 package com.android.launcher3.icons
17 
18 import android.graphics.Canvas
19 import android.graphics.Color
20 import android.graphics.Paint
21 import androidx.test.ext.junit.runners.AndroidJUnit4
22 import androidx.test.platform.app.InstrumentationRegistry
23 import com.android.launcher3.icons.UserBadgeDrawable.SHADOW_COLOR
24 import com.google.common.truth.Truth.assertThat
25 import org.junit.Test
26 import org.junit.runner.RunWith
27 import org.mockito.kotlin.any
28 import org.mockito.kotlin.mock
29 import org.mockito.kotlin.whenever
30 
31 /** Test for [UserBadgeDrawable] */
32 @RunWith(AndroidJUnit4::class)
33 class UserBadgeDrawableTest {
34     private val context = InstrumentationRegistry.getInstrumentation().targetContext
35     private val canvas = mock<Canvas>()
36     private val systemUnderTest =
37         UserBadgeDrawable(context, R.drawable.ic_work_app_badge, R.color.badge_tint_work, false)
38 
39     @Test
draw_opaquenull40     fun draw_opaque() {
41         val colorList = mutableListOf<Int>()
42         whenever(
43             canvas.drawCircle(
44                 any(),
45                 any(),
46                 any(),
47                 any()
48             )
49         ).then { colorList.add(it.getArgument<Paint>(3).color) }
50 
51         systemUnderTest.alpha = 255
52         systemUnderTest.draw(canvas)
53 
54         assertThat(colorList).containsExactly(SHADOW_COLOR, Color.WHITE)
55     }
56 
57     @Test
draw_transparentnull58     fun draw_transparent() {
59         val colorList = mutableListOf<Int>()
60         whenever(
61             canvas.drawCircle(
62                 any(),
63                 any(),
64                 any(),
65                 any()
66             )
67         ).then { colorList.add(it.getArgument<Paint>(3).color) }
68 
69         systemUnderTest.alpha = 0
70         systemUnderTest.draw(canvas)
71 
72         assertThat(colorList).hasSize(2)
73         assertThat(Color.valueOf(colorList[0]).alpha()).isEqualTo(0)
74         assertThat(Color.valueOf(colorList[1]).alpha()).isEqualTo(0)
75     }
76 }
77