Skip to content

Commit 3be1513

Browse files
author
Maxime NATUREL
committed
Adding unit tests
1 parent bf502f4 commit 3be1513

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (c) 2022 New Vector Ltd
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 im.vector.app.features.settings.devices.v2.list
18+
19+
import android.widget.ImageView
20+
import androidx.annotation.DrawableRes
21+
import androidx.annotation.StringRes
22+
import im.vector.app.R
23+
import im.vector.app.test.fakes.FakeStringProvider
24+
import io.mockk.mockk
25+
import io.mockk.verifyAll
26+
import org.junit.Test
27+
28+
private const val A_DESCRIPTION = "description"
29+
30+
class SetDeviceTypeIconUseCaseTest {
31+
32+
private val fakeStringProvider = FakeStringProvider()
33+
34+
private val setDeviceTypeIconUseCase = SetDeviceTypeIconUseCase()
35+
36+
@Test
37+
fun `given a device type when execute then correct icon and description is set to the ImageView`() {
38+
testType(
39+
deviceType = DeviceType.UNKNOWN,
40+
drawableResId = R.drawable.ic_device_type_unknown,
41+
descriptionResId = R.string.a11y_device_manager_device_type_unknown
42+
)
43+
44+
testType(
45+
deviceType = DeviceType.MOBILE,
46+
drawableResId = R.drawable.ic_device_type_mobile,
47+
descriptionResId = R.string.a11y_device_manager_device_type_mobile
48+
)
49+
50+
testType(
51+
deviceType = DeviceType.WEB,
52+
drawableResId = R.drawable.ic_device_type_web,
53+
descriptionResId = R.string.a11y_device_manager_device_type_web
54+
)
55+
56+
testType(
57+
deviceType = DeviceType.DESKTOP,
58+
drawableResId = R.drawable.ic_device_type_desktop,
59+
descriptionResId = R.string.a11y_device_manager_device_type_desktop
60+
)
61+
}
62+
63+
private fun testType(deviceType: DeviceType, @DrawableRes drawableResId: Int, @StringRes descriptionResId: Int) {
64+
// Given
65+
val imageView = mockk<ImageView>(relaxUnitFun = true)
66+
fakeStringProvider.given(descriptionResId, A_DESCRIPTION)
67+
68+
// When
69+
setDeviceTypeIconUseCase.execute(deviceType, imageView, fakeStringProvider.instance)
70+
71+
// Then
72+
verifyAll {
73+
imageView.setImageResource(drawableResId)
74+
imageView.contentDescription = A_DESCRIPTION
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)