unitest is pending
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package com.example.hpostesting
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import android.view.View
|
||||
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 org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.ArgumentMatchers.any
|
||||
import org.mockito.ArgumentMatchers.anyString
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.MockitoAnnotations
|
||||
|
||||
class HemocubeViewModelTest {
|
||||
@Mock
|
||||
private lateinit var mockSharedPreferences: SharedPreferences
|
||||
|
||||
@Mock
|
||||
private lateinit var mockActivity: HemocubeActivity // Replace with your actual Activity class
|
||||
|
||||
@Mock
|
||||
private lateinit var mockBinding: FragmentHemoCubeReferenceBinding // Replace with your actual Binding class
|
||||
|
||||
private lateinit var hemoCubeFragment: HemoCubeFragment
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
hemoCubeFragment = HemoCubeFragment()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `handleValidResult with valid input`() {
|
||||
// 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)
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
|
||||
// Add more test cases for different scenarios if needed
|
||||
}
|
||||
Reference in New Issue
Block a user