62 lines
2.0 KiB
Kotlin
62 lines
2.0 KiB
Kotlin
package com.example.hpostesting
|
|
|
|
class DeviceFragmentTest {
|
|
//
|
|
// @Mock
|
|
// private lateinit var sharedPreferences: SharedPreferences
|
|
//
|
|
// @Mock
|
|
// private lateinit var hemoCubeViewModel: HemoCubeViewModel
|
|
//
|
|
// private lateinit var scenario: FragmentScenario<DeviceFragment>
|
|
//
|
|
// @Before
|
|
// fun setup() {
|
|
// MockitoAnnotations.openMocks(this)
|
|
// // Mock the ViewModel and SharedPreferences
|
|
// `when`(hemoCubeViewModel.progressBar).thenReturn(MutableLiveData())
|
|
// `when`(hemoCubeViewModel.messages).thenReturn(MutableLiveData())
|
|
//
|
|
// `when`(sharedPreferences.getString(Constants.DEVICE_ID, "")).thenReturn("mockedDeviceId")
|
|
//
|
|
// // Launch the fragment in a test container
|
|
// scenario = launchFragmentInContainer(themeResId = R.style.Theme_AppCompat) {
|
|
// DeviceFragment().apply {
|
|
// deviceViewModel = hemoCubeViewModel
|
|
// }
|
|
// }
|
|
// scenario.onFragment { fragment ->
|
|
// fragment.sharedPreferences = sharedPreferences
|
|
// }
|
|
// }
|
|
//
|
|
// @After
|
|
// fun tearDown() {
|
|
// scenario.moveToState(Lifecycle.State.DESTROYED)
|
|
// }
|
|
//
|
|
// @Test
|
|
// fun testGetDeviceId() {
|
|
// // Mock UsbService and its behavior
|
|
// val usbService = (scenario.activity as DeviceActivity).mService
|
|
// `when`(usbService.sendAndListenToHemoCube(
|
|
// eq(HemoCubeCommands.DEVICE_CONFIGURATION_COMMAND),
|
|
// any(UsbServiceListener::class.java)
|
|
// )).thenAnswer {
|
|
// val listener = it.arguments[1] as UsbServiceListener
|
|
// listener.onUsbRead("MockedDeviceId".toByteArray())
|
|
// }
|
|
//
|
|
// // Trigger the method to be tested
|
|
// scenario.onFragment {
|
|
// it.getDeviceId()
|
|
// }
|
|
//
|
|
// // Verify that the shared preferences were updated
|
|
// verify(sharedPreferences.edit()).putString(Constants.DEVICE_ID, "MockedDeviceId")
|
|
// verify(sharedPreferences.edit()).apply()
|
|
// }
|
|
|
|
// Similar tests can be written for other methods
|
|
}
|