2023-11-06 12:36:50 +05:30
|
|
|
package com.example.hpostesting
|
|
|
|
|
|
2024-01-18 01:53:41 +05:30
|
|
|
import android.content.Context
|
2023-11-06 12:36:50 +05:30
|
|
|
import android.content.SharedPreferences
|
2024-01-18 01:53:41 +05:30
|
|
|
import com.example.hpostesting.data.dao.HemoCubeBufferDao
|
|
|
|
|
import com.example.hpostesting.data.dao.HemoCubeDao
|
|
|
|
|
import com.example.hpostesting.data.datasource.LocalFileDataSource
|
|
|
|
|
import com.example.hpostesting.data.repository.DatabaseRepository
|
|
|
|
|
import com.example.hpostesting.data.repository.Repository
|
|
|
|
|
import com.example.hpostesting.domain.LogFileManager
|
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.anyString
|
|
|
|
|
import org.mockito.Mock
|
|
|
|
|
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
|
|
|
|
|
|
2024-01-18 01:53:41 +05:30
|
|
|
@Mock
|
|
|
|
|
private lateinit var mockContext: Context
|
|
|
|
|
|
|
|
|
|
@Mock
|
|
|
|
|
private lateinit var hemoCubeDaoMock: HemoCubeDao
|
|
|
|
|
|
|
|
|
|
@Mock
|
|
|
|
|
private lateinit var mockRepository: Repository
|
|
|
|
|
|
|
|
|
|
@Mock
|
|
|
|
|
private lateinit var mockHemoCubeBufferDao: HemoCubeBufferDao
|
|
|
|
|
|
|
|
|
|
// @Mock
|
|
|
|
|
// private lateinit var mockLogFileManager: LogFileManager
|
|
|
|
|
//
|
|
|
|
|
// @Mock
|
|
|
|
|
// private lateinit var mockLocalFileDataSource: LocalFileDataSource
|
|
|
|
|
|
2023-11-06 12:36:50 +05:30
|
|
|
private lateinit var hemoCubeFragment: HemoCubeFragment
|
|
|
|
|
|
2024-01-18 01:53:41 +05:30
|
|
|
private lateinit var hemoCubeViewModel: HemoCubeViewModel
|
|
|
|
|
|
2023-11-06 12:36:50 +05:30
|
|
|
@Before
|
|
|
|
|
fun setUp() {
|
2024-01-18 01:53:41 +05:30
|
|
|
MockitoAnnotations.openMocks(this)
|
2023-11-06 12:36:50 +05:30
|
|
|
hemoCubeFragment = HemoCubeFragment()
|
2024-01-18 01:53:41 +05:30
|
|
|
// hemoCubeViewModel = HemoCubeViewModel(hemoCubeDaoMock, mockHemoCubeBufferDao, mockRepository, mockLogFileManager, mockLocalFileDataSource, mockContext)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `parseData test`() {
|
|
|
|
|
assertEquals(1, 1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `getCurrentDate returns date`() {
|
|
|
|
|
// `when`(hemoCubeViewModel.getCurrentDate()).thenReturn("1705429433")
|
|
|
|
|
//
|
|
|
|
|
// val result = hemoCubeViewModel.getCurrentDate()
|
|
|
|
|
//
|
|
|
|
|
// assertEquals("1705429433", hemoCubeViewModel.getCurrentDate())
|
2023-11-06 12:36:50 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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
|
|
|
}
|