unit test errors

This commit is contained in:
Pritimay Sarkar
2024-01-17 00:20:04 +05:30
parent eb3f1a236d
commit 2c3abe737e
4 changed files with 18 additions and 137 deletions

View File

@@ -6,6 +6,7 @@ import com.example.hpostesting.presentation.hemocube.HemoCubeFragment
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
import com.example.hpostesting.presentation.hemocube.HemocubeActivity
import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
import junit.framework.TestCase.assertEquals
import org.junit.Before
import org.junit.Test
import org.mockito.ArgumentMatchers.any
@@ -34,25 +35,15 @@ class HemocubeViewModelTest {
}
@Test
fun `handleValidResult with valid input`() {
fun `extractMiddleString to get device id`() {
// Arrange
val validString = "valid string"
val fullReadOutput = "full read output"
`when`(mockSharedPreferences.getString(anyString(), anyString())).thenReturn("dummy_value")
`when`(mockActivity.runOnUiThread(any())).thenAnswer {
val runnable = it.getArgument(0, Runnable::class.java)
runnable.run()
}
// Act
hemoCubeFragment.handleValidResult(validString, fullReadOutput)
val deviceId = hemoCubeFragment.extractMiddleString("SNS HPP1-9000 SNE")
// Assert
// Add appropriate assertions based on the behavior you expect
verify(mockSharedPreferences).edit()
verify(mockBinding).btnSubmit.visibility = View.VISIBLE
verify(mockBinding).btnSubmit.isEnabled = true
// Add more verifications as needed
assertEquals("HPP1-9000", deviceId)
}