84 lines
2.4 KiB
Kotlin
84 lines
2.4 KiB
Kotlin
|
|
package com.example.hpostesting
|
||
|
|
|
||
|
|
import android.content.SharedPreferences
|
||
|
|
import com.example.hpostesting.presentation.hemocube.HemoCubeFragment
|
||
|
|
import com.example.hpostesting.presentation.hemocube.HemocubeActivity
|
||
|
|
import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
|
||
|
|
import junit.framework.TestCase
|
||
|
|
import org.junit.Before
|
||
|
|
import org.junit.Test
|
||
|
|
import org.mockito.ArgumentMatchers
|
||
|
|
import org.mockito.Mock
|
||
|
|
import org.mockito.Mockito
|
||
|
|
import org.mockito.MockitoAnnotations
|
||
|
|
|
||
|
|
class HemoCubeFragmentTest {
|
||
|
|
|
||
|
|
@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 `extractMiddleString to get device id`() {
|
||
|
|
// Arrange
|
||
|
|
Mockito.`when`(
|
||
|
|
mockSharedPreferences.getString(
|
||
|
|
ArgumentMatchers.anyString(),
|
||
|
|
ArgumentMatchers.anyString()
|
||
|
|
)
|
||
|
|
).thenReturn("dummy_value")
|
||
|
|
|
||
|
|
// Act
|
||
|
|
val deviceId = hemoCubeFragment.extractMiddleString("SNS HPP1-9000 SNE")
|
||
|
|
|
||
|
|
// Assert
|
||
|
|
TestCase.assertEquals("HPP1-9000", deviceId)
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test
|
||
|
|
fun `updateDeviceId in shared pref`() {
|
||
|
|
// Arrange
|
||
|
|
Mockito.`when`(
|
||
|
|
mockSharedPreferences.getString(
|
||
|
|
ArgumentMatchers.anyString(),
|
||
|
|
ArgumentMatchers.anyString()
|
||
|
|
)
|
||
|
|
).thenReturn("HPP1-0001")
|
||
|
|
|
||
|
|
// Act
|
||
|
|
val deviceId = mockSharedPreferences.getString(
|
||
|
|
ArgumentMatchers.anyString(),
|
||
|
|
ArgumentMatchers.anyString()
|
||
|
|
)
|
||
|
|
|
||
|
|
// Assert
|
||
|
|
TestCase.assertEquals("HPP1-0001", deviceId)
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test
|
||
|
|
fun `allReadingsComplete check`() {
|
||
|
|
// Arrange
|
||
|
|
val repeatReadingCount = 1
|
||
|
|
val readingsPerSample = 1
|
||
|
|
|
||
|
|
// Act
|
||
|
|
val result = hemoCubeFragment.allReadingsComplete(repeatReadingCount, readingsPerSample)
|
||
|
|
|
||
|
|
// Assert
|
||
|
|
TestCase.assertEquals(true, result)
|
||
|
|
TestCase.assertEquals(hemoCubeFragment.allReadingsComplete(0, 1), false)
|
||
|
|
}
|
||
|
|
}
|