[go: nahoru, domu]

blob: 0d48e641a23ddbd892e2020281e3570755262d43 [file] [log] [blame]
Haoyu Zhangc38bed12019-12-05 14:38:45 -08001/*
2 * Copyright 2019 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
Louis Pullen-Freilicha2be36b2020-07-21 21:35:11 +010017package androidx.compose.ui.text.android.style
Haoyu Zhangc38bed12019-12-05 14:38:45 -080018
19import android.text.TextPaint
20import androidx.test.filters.SmallTest
Louis Pullen-Freilicha2be36b2020-07-21 21:35:11 +010021import androidx.compose.ui.text.android.InternalPlatformTextApi
Haoyu Zhangc38bed12019-12-05 14:38:45 -080022import com.nhaarman.mockitokotlin2.any
23import com.nhaarman.mockitokotlin2.doReturn
24import com.nhaarman.mockitokotlin2.mock
25import com.nhaarman.mockitokotlin2.never
26import com.nhaarman.mockitokotlin2.verify
27import org.junit.Test
28import org.junit.runner.RunWith
29import org.junit.runners.JUnit4
30
Siyamed Sinir21f73482020-06-17 11:36:22 -070031@OptIn(InternalPlatformTextApi::class)
Haoyu Zhangc38bed12019-12-05 14:38:45 -080032@SmallTest
33@RunWith(JUnit4::class)
34class LetterSpacingSpanPxTest {
35 @Test
36 fun updateDrawState() {
37 val letterSpacing = 10f
38 val textSize = 10f
39 val textScaleX = 2f
40
41 val letterSpacingSpanPx = LetterSpacingSpanPx(letterSpacing)
42
43 val textPaint = mock<TextPaint> {
44 on { this.textSize } doReturn textSize
45 on { this.textScaleX } doReturn textScaleX
46 }
47
48 letterSpacingSpanPx.updateDrawState(textPaint)
49
50 verify(textPaint).letterSpacing = 0.5f
51 }
52
53 @Test
54 fun updateDrawState_with_invalid_textSize() {
55 val letterSpacing = 10f
56 val textSize = 0f
57 val textScaleX = 2f
58
59 val letterSpacingSpanPx = LetterSpacingSpanPx(letterSpacing)
60
61 val textPaint = mock<TextPaint> {
62 on { this.textSize } doReturn textSize
63 on { this.textScaleX } doReturn textScaleX
64 }
65
66 letterSpacingSpanPx.updateDrawState(textPaint)
67
68 verify(textPaint, never()).letterSpacing = any()
69 }
70
71 @Test
72 fun updateMeasureState() {
73 val letterSpacing = 10f
74 val textSize = 10f
75 val textScaleX = 2f
76
77 val letterSpacingSpanPx = LetterSpacingSpanPx(letterSpacing)
78
79 val textPaint = mock<TextPaint> {
80 on { this.textSize } doReturn textSize
81 on { this.textScaleX } doReturn textScaleX
82 }
83
84 letterSpacingSpanPx.updateMeasureState(textPaint)
85
86 verify(textPaint).letterSpacing = 0.5f
87 }
88
89 @Test
90 fun updateMeasureState_with_invalid_textSize() {
91 val letterSpacing = 10f
92 val textSize = 0f
93 val textScaleX = 2f
94
95 val letterSpacingSpanPx = LetterSpacingSpanPx(letterSpacing)
96
97 val textPaint = mock<TextPaint> {
98 on { this.textSize } doReturn textSize
99 on { this.textScaleX } doReturn textScaleX
100 }
101
102 letterSpacingSpanPx.updateMeasureState(textPaint)
103
104 verify(textPaint, never()).letterSpacing = any()
105 }
106}