@@ -27,7 +27,15 @@ import org.kabiri.android.usbterminal.util.IResourceProvider
27
27
import org.kabiri.android.usbterminal.util.isCloneArduinoBoard
28
28
import org.kabiri.android.usbterminal.util.isOfficialArduinoBoard
29
29
30
- private const val OFFICIAL_VENDOR_ID = 0x0043
30
+ private const val OFFICIAL_VENDOR_ID = 0x2341
31
+ private const val OFFICIAL_PRODUCT_ID = 0x0043
32
+
33
+ private const val CLONE_VENDOR_ID = 0x1A86
34
+ private const val CLONE_PRODUCT_ID = 0x7523
35
+
36
+
37
+ private const val OTHER_VENDOR_ID = 0x1234 // random id
38
+ private const val OTHER_PRODUCT_ID = 0x1234 // random id
31
39
32
40
@OptIn(ExperimentalCoroutinesApi ::class )
33
41
internal class MainActivityViewModelTest {
@@ -119,9 +127,8 @@ internal class MainActivityViewModelTest {
119
127
val expectedInfo = " connecting anyways"
120
128
121
129
val fakeDevice: UsbDevice = mockk(relaxed = true )
122
- mockkStatic(UsbDevice ::isOfficialArduinoBoard, UsbDevice ::isCloneArduinoBoard)
123
- every { fakeDevice.isOfficialArduinoBoard() } returns false
124
- every { fakeDevice.isCloneArduinoBoard() } returns false
130
+ every { fakeDevice.vendorId } returns OTHER_VENDOR_ID
131
+ every { fakeDevice.productId } returns OTHER_PRODUCT_ID
125
132
126
133
every { mockUsbUseCase.scanForUsbDevices() } returns listOf (fakeDevice)
127
134
every { mockResourceProvider.getString(R .string.helper_error_arduino_device_not_found) } returns expectedError
@@ -136,38 +143,15 @@ internal class MainActivityViewModelTest {
136
143
verify(exactly = 1 ) { mockUsbUseCase.requestPermission(fakeDevice) }
137
144
}
138
145
139
- @Test
140
- fun `connect emits expected message and calls requestPermission when the device is neither official nor a clone` () =
141
- runTest {
142
- // arrange
143
- val expected = " connecting anyways"
144
-
145
- val fakeDevice: UsbDevice = mockk(relaxed = true )
146
- mockkStatic(UsbDevice ::isOfficialArduinoBoard, UsbDevice ::isCloneArduinoBoard)
147
- every { fakeDevice.isOfficialArduinoBoard() } returns false
148
- every { fakeDevice.isCloneArduinoBoard() } returns false
149
-
150
- every { mockUsbUseCase.scanForUsbDevices() } returns listOf (fakeDevice)
151
- every { mockResourceProvider.getString(R .string.helper_error_connecting_anyway) } returns expected
152
-
153
- // act
154
- sut.connect()
155
-
156
- // assert
157
- assertThat(sut.infoMessage.value).isEqualTo(expected)
158
- verify(exactly = 1 ) { mockUsbUseCase.requestPermission(fakeDevice) }
159
- }
160
-
161
146
@Test
162
147
fun `connect emits expected message and calls requestPermission when the device is a clone` () =
163
148
runTest {
164
149
// arrange
165
150
val expected = " connecting anyways"
166
151
167
152
val fakeDevice: UsbDevice = mockk(relaxed = true )
168
- mockkStatic(UsbDevice ::isOfficialArduinoBoard, UsbDevice ::isCloneArduinoBoard)
169
- every { fakeDevice.isOfficialArduinoBoard() } returns false
170
- every { fakeDevice.isCloneArduinoBoard() } returns true
153
+ every { fakeDevice.vendorId } returns CLONE_VENDOR_ID
154
+ every { fakeDevice.productId } returns CLONE_PRODUCT_ID
171
155
172
156
every { mockUsbUseCase.scanForUsbDevices() } returns listOf (fakeDevice)
173
157
every { mockResourceProvider.getString(R .string.helper_error_connecting_anyway) } returns expected
@@ -185,9 +169,8 @@ internal class MainActivityViewModelTest {
185
169
runTest {
186
170
// arrange
187
171
val fakeDevice: UsbDevice = mockk(relaxed = true )
188
- mockkStatic(UsbDevice ::isOfficialArduinoBoard, UsbDevice ::isCloneArduinoBoard)
189
- every { fakeDevice.isOfficialArduinoBoard() } returns true
190
- every { fakeDevice.isCloneArduinoBoard() } returns false
172
+ every { fakeDevice.vendorId } returns OFFICIAL_VENDOR_ID
173
+ every { fakeDevice.productId } returns OFFICIAL_PRODUCT_ID
191
174
192
175
every { mockUsbUseCase.scanForUsbDevices() } returns listOf (fakeDevice)
193
176
0 commit comments