2023-11-06 12:36:50 +05:30
|
|
|
package com.example.hpostesting
|
|
|
|
|
|
|
|
|
|
import android.content.SharedPreferences
|
|
|
|
|
import android.view.View
|
2024-01-17 02:44:33 +05:30
|
|
|
import com.example.hpostesting.data.constant.Constants
|
2023-11-06 12:36:50 +05:30
|
|
|
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
|
2024-01-17 00:20:04 +05:30
|
|
|
import junit.framework.TestCase.assertEquals
|
2023-11-06 12:36:50 +05:30
|
|
|
import org.junit.Before
|
|
|
|
|
import org.junit.Test
|
|
|
|
|
import org.mockito.ArgumentMatchers.any
|
|
|
|
|
import org.mockito.ArgumentMatchers.anyString
|
2024-01-17 02:44:33 +05:30
|
|
|
import org.mockito.ArgumentMatchers.eq
|
2023-11-06 12:36:50 +05:30
|
|
|
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
|
2024-01-17 00:20:04 +05:30
|
|
|
fun `extractMiddleString to get device id`() {
|
2023-11-06 12:36:50 +05:30
|
|
|
// Arrange
|
|
|
|
|
`when`(mockSharedPreferences.getString(anyString(), anyString())).thenReturn("dummy_value")
|
|
|
|
|
|
|
|
|
|
// Act
|
2024-01-17 00:20:04 +05:30
|
|
|
val deviceId = hemoCubeFragment.extractMiddleString("SNS HPP1-9000 SNE")
|
2023-11-06 12:36:50 +05:30
|
|
|
|
|
|
|
|
// Assert
|
2024-01-17 00:20:04 +05:30
|
|
|
assertEquals("HPP1-9000", deviceId)
|
2023-11-06 12:36:50 +05:30
|
|
|
}
|
|
|
|
|
|
2024-01-17 02:44:33 +05:30
|
|
|
@Test
|
|
|
|
|
fun `updateDeviceId in shared pref`() {
|
|
|
|
|
// Arrange
|
|
|
|
|
`when`(mockSharedPreferences.getString(anyString(), anyString())).thenReturn("HPP1-0001")
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
val deviceId = mockSharedPreferences.getString(anyString(), anyString())
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
assertEquals("HPP1-0001", deviceId)
|
|
|
|
|
}
|
2023-11-06 12:36:50 +05:30
|
|
|
|
2024-01-17 02:44:33 +05:30
|
|
|
@Test
|
|
|
|
|
fun `allReadingsComplete check`() {
|
|
|
|
|
// Arrange
|
|
|
|
|
val repeatReadingCount = 1
|
|
|
|
|
val readingsPerSample = 1
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
val result = hemoCubeFragment.allReadingsComplete(repeatReadingCount, readingsPerSample)
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
assertEquals(true, result)
|
|
|
|
|
assertEquals(hemoCubeFragment.allReadingsComplete(0, 1), false)
|
|
|
|
|
}
|
2023-11-06 12:36:50 +05:30
|
|
|
}
|