Handler(Looper.getMainLooper()).postDelayed(
{
println("inside the looper")
val firmwareVersion = managerService.getDeviceFirmwareVersion();
fwStatus = if (!firmwareVersion.isNullOrEmpty()) "$versionValue $firmwareVersion" else "--"
UpdateManagerInstance.disconnectFromUpdateService()
}, 2000)
is there anyway to tackle this block of code on Unit test kotlin mockito?
In Android unit testing, you might need to mock the Handler or Looper to test code that involves background threads or delayed operations. Here's how you can mock a Handler and Looper in Kotlin unit tests:
Replace 'x.y.z' with the latest version of Mockito available.
In your unit test, you can mock the Handler using Mockito:
By creating a mock Handler with Mockito, you can control its behavior during your tests.
Mocking the Looper in this way allows you to control the behavior of the Handler since Handler relies on the provided Looper.
Remember that Mockito allows you to define the behavior of these mock objects by using its when and thenReturn methods. This way, you can simulate the expected behavior of the Handler or Looper during your unit tests.