75 percentage cover on calibration
This commit is contained in:
@@ -91,6 +91,12 @@ dependencies {
|
|||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||||
|
androidTestImplementation "androidx.work:work-testing-ktx:2.9.0"
|
||||||
|
androidTestImplementation 'androidx.test:core-ktx:1.5.0'
|
||||||
|
|
||||||
|
// mockk
|
||||||
|
testImplementation 'io.mockk:mockk:1.10.6'
|
||||||
|
|
||||||
// Mockito dependencies
|
// Mockito dependencies
|
||||||
testImplementation 'org.mockito:mockito-core:3.12.4'
|
testImplementation 'org.mockito:mockito-core:3.12.4'
|
||||||
androidTestImplementation 'org.mockito:mockito-android:3.12.4'
|
androidTestImplementation 'org.mockito:mockito-android:3.12.4'
|
||||||
|
|||||||
@@ -7,154 +7,13 @@ import java.io.File
|
|||||||
import java.io.FileWriter
|
import java.io.FileWriter
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
class LocalFileDataSource {
|
interface LocalFileDataSource {
|
||||||
|
|
||||||
fun saveCsvToDisk(filepath: String, contents: ArrayList<Array<String>>) {
|
fun saveCsvToDisk(filepath: String, contents: ArrayList<Array<String>>)
|
||||||
val writer = CSVWriter(FileWriter(filepath))
|
|
||||||
writer.writeAll(contents) // data is adding to csv
|
|
||||||
writer.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun saveTextToDisk(filepath: String, contents: String) {
|
fun saveTextToDisk(filepath: String, contents: String)
|
||||||
val writer = FileWriter(File(filepath))
|
|
||||||
|
|
||||||
writer.append(contents)
|
|
||||||
writer.flush()
|
|
||||||
writer.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun exportDataToCSV(
|
fun exportDataToCSV(
|
||||||
fileName: String, dataList: List<HemoCubeTestData>
|
fileName: String, dataList: List<HemoCubeTestData>
|
||||||
): Boolean {
|
): Boolean
|
||||||
try {
|
|
||||||
val formattedFileName = fileName.replace(Regex("[^a-zA-Z0-9.-]"), "_") // Replace special characters with underscores
|
|
||||||
val filePath = File(getExternalStorageDirectory(), formattedFileName)
|
|
||||||
val writer = FileWriter(filePath)
|
|
||||||
val csvWriter = CSVWriter(writer)
|
|
||||||
// Write CSV header
|
|
||||||
val header = arrayOf(
|
|
||||||
"_id",
|
|
||||||
"name",
|
|
||||||
"incubationTime",
|
|
||||||
"bloodGroup",
|
|
||||||
"birthYear", // Include other fields from the data class
|
|
||||||
"state",
|
|
||||||
"abhaId",
|
|
||||||
"userImageURL",
|
|
||||||
"location",
|
|
||||||
"reportUploadTime",
|
|
||||||
"testType",
|
|
||||||
"testTime",
|
|
||||||
"testStatus",
|
|
||||||
"gender",
|
|
||||||
"localFlag", // Add more fields as necessary
|
|
||||||
"deviceId",
|
|
||||||
"appVersion",
|
|
||||||
"deviceSerialNumber",
|
|
||||||
"deviceType",
|
|
||||||
"kitSerial",
|
|
||||||
"resultData",
|
|
||||||
"led1Buffer",
|
|
||||||
"led2Buffer",
|
|
||||||
"led3Buffer",
|
|
||||||
"led4Buffer",
|
|
||||||
"led1Sample",
|
|
||||||
"led2Sample",
|
|
||||||
"led3Sample",
|
|
||||||
"led4Sample",
|
|
||||||
"led1Average",
|
|
||||||
"led2Average",
|
|
||||||
"led3Average",
|
|
||||||
"led4Average",
|
|
||||||
"abs1",
|
|
||||||
"abs2",
|
|
||||||
"abs3",
|
|
||||||
"abs4",
|
|
||||||
"deviceRatio",
|
|
||||||
"calculatedRatio",
|
|
||||||
"predictedDenovixRatio",
|
|
||||||
"coefficients",
|
|
||||||
"classificationResult",
|
|
||||||
"prdClassification",
|
|
||||||
"errorMessages",
|
|
||||||
"batteryLevel",
|
|
||||||
"batteryCapacity",
|
|
||||||
"batteryMaxCapacity",
|
|
||||||
"batteryTemperature",
|
|
||||||
"batteryVoltage"
|
|
||||||
)
|
|
||||||
csvWriter.writeNext(header)
|
|
||||||
|
|
||||||
// Write data rows
|
|
||||||
for (data in dataList) {
|
|
||||||
val row = arrayOf(
|
|
||||||
data._id,
|
|
||||||
data.name,
|
|
||||||
data.incubationTime,
|
|
||||||
data.bloodGroup,
|
|
||||||
data.birthYear, // Include other fields similarly
|
|
||||||
data.state,
|
|
||||||
data.abhaId,
|
|
||||||
data.userImageURL,
|
|
||||||
data.location?.toString(),
|
|
||||||
data.reportUploadTime ?: "",
|
|
||||||
data.testType ?: "",
|
|
||||||
data.testTime ?: "",
|
|
||||||
data.testStatus?.toString() ?: "",
|
|
||||||
data.gender,
|
|
||||||
data.localFlag.toString(),
|
|
||||||
data.deviceId ?: "",
|
|
||||||
data.appVersion ?: "",
|
|
||||||
data.deviceSerialNumber,
|
|
||||||
data.deviceType,
|
|
||||||
data.kitSerial,
|
|
||||||
data.resultData,
|
|
||||||
data.led1Buffer?.toString() ?: "",
|
|
||||||
data.led2Buffer?.toString() ?: "",
|
|
||||||
data.led3Buffer?.toString() ?: "",
|
|
||||||
data.led4Buffer?.toString() ?: "",
|
|
||||||
data.led1Sample?.toString() ?: "",
|
|
||||||
data.led2Sample?.toString() ?: "",
|
|
||||||
data.led3Sample?.toString() ?: "",
|
|
||||||
data.led4Sample?.toString() ?: "",
|
|
||||||
data.led1Average?.toString() ?: "",
|
|
||||||
data.led2Average?.toString() ?: "",
|
|
||||||
data.led3Average?.toString() ?: "",
|
|
||||||
data.led4Average?.toString() ?: "",
|
|
||||||
data.abs1?.toString() ?: "",
|
|
||||||
data.abs2?.toString() ?: "",
|
|
||||||
data.abs3?.toString() ?: "",
|
|
||||||
data.abs4?.toString() ?: "",
|
|
||||||
data.deviceRatio?.toString() ?: "",
|
|
||||||
data.calculatedRatio?.toString() ?: "",
|
|
||||||
data.predictedDenovixRatio?.toString() ?: "",
|
|
||||||
data.coefficients ?: "",
|
|
||||||
data.classificationResult,
|
|
||||||
data.prdClassification,
|
|
||||||
data.errorMessages,
|
|
||||||
data.batteryLevel,
|
|
||||||
data.batteryCapacity,
|
|
||||||
data.batteryMaxCapacity,
|
|
||||||
data.batteryTemperature,
|
|
||||||
data.batteryVoltage
|
|
||||||
)
|
|
||||||
csvWriter.writeNext(row)
|
|
||||||
}
|
|
||||||
writer.close()
|
|
||||||
return true
|
|
||||||
} catch (e: IOException) {
|
|
||||||
e.printStackTrace()
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getExternalStorageDirectory(): File {
|
|
||||||
val folder = File(Environment.getExternalStorageDirectory(), "HposFolder")
|
|
||||||
|
|
||||||
if (!folder.exists()) {
|
|
||||||
folder.mkdirs()
|
|
||||||
}
|
|
||||||
|
|
||||||
return folder
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,161 @@
|
|||||||
|
package com.example.hpostesting.data.datasource
|
||||||
|
|
||||||
|
import android.os.Environment
|
||||||
|
import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
||||||
|
import com.opencsv.CSVWriter
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileWriter
|
||||||
|
import java.io.IOException
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class LocalFileDataSourceImpl @Inject constructor(): LocalFileDataSource {
|
||||||
|
|
||||||
|
override fun saveCsvToDisk(filepath: String, contents: ArrayList<Array<String>>) {
|
||||||
|
val writer = CSVWriter(FileWriter(filepath))
|
||||||
|
writer.writeAll(contents) // data is adding to csv
|
||||||
|
writer.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun saveTextToDisk(filepath: String, contents: String) {
|
||||||
|
val writer = FileWriter(File(filepath))
|
||||||
|
|
||||||
|
writer.append(contents)
|
||||||
|
writer.flush()
|
||||||
|
writer.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun exportDataToCSV(
|
||||||
|
fileName: String, dataList: List<HemoCubeTestData>
|
||||||
|
): Boolean {
|
||||||
|
try {
|
||||||
|
val formattedFileName = fileName.replace(Regex("[^a-zA-Z0-9.-]"), "_") // Replace special characters with underscores
|
||||||
|
val filePath = File(getExternalStorageDirectory(), formattedFileName)
|
||||||
|
val writer = FileWriter(filePath)
|
||||||
|
val csvWriter = CSVWriter(writer)
|
||||||
|
// Write CSV header
|
||||||
|
val header = arrayOf(
|
||||||
|
"_id",
|
||||||
|
"name",
|
||||||
|
"incubationTime",
|
||||||
|
"bloodGroup",
|
||||||
|
"birthYear", // Include other fields from the data class
|
||||||
|
"state",
|
||||||
|
"abhaId",
|
||||||
|
"userImageURL",
|
||||||
|
"location",
|
||||||
|
"reportUploadTime",
|
||||||
|
"testType",
|
||||||
|
"testTime",
|
||||||
|
"testStatus",
|
||||||
|
"gender",
|
||||||
|
"localFlag", // Add more fields as necessary
|
||||||
|
"deviceId",
|
||||||
|
"appVersion",
|
||||||
|
"deviceSerialNumber",
|
||||||
|
"deviceType",
|
||||||
|
"kitSerial",
|
||||||
|
"resultData",
|
||||||
|
"led1Buffer",
|
||||||
|
"led2Buffer",
|
||||||
|
"led3Buffer",
|
||||||
|
"led4Buffer",
|
||||||
|
"led1Sample",
|
||||||
|
"led2Sample",
|
||||||
|
"led3Sample",
|
||||||
|
"led4Sample",
|
||||||
|
"led1Average",
|
||||||
|
"led2Average",
|
||||||
|
"led3Average",
|
||||||
|
"led4Average",
|
||||||
|
"abs1",
|
||||||
|
"abs2",
|
||||||
|
"abs3",
|
||||||
|
"abs4",
|
||||||
|
"deviceRatio",
|
||||||
|
"calculatedRatio",
|
||||||
|
"predictedDenovixRatio",
|
||||||
|
"coefficients",
|
||||||
|
"classificationResult",
|
||||||
|
"prdClassification",
|
||||||
|
"errorMessages",
|
||||||
|
"batteryLevel",
|
||||||
|
"batteryCapacity",
|
||||||
|
"batteryMaxCapacity",
|
||||||
|
"batteryTemperature",
|
||||||
|
"batteryVoltage"
|
||||||
|
)
|
||||||
|
csvWriter.writeNext(header)
|
||||||
|
|
||||||
|
// Write data rows
|
||||||
|
for (data in dataList) {
|
||||||
|
val row = arrayOf(
|
||||||
|
data._id,
|
||||||
|
data.name,
|
||||||
|
data.incubationTime,
|
||||||
|
data.bloodGroup,
|
||||||
|
data.birthYear, // Include other fields similarly
|
||||||
|
data.state,
|
||||||
|
data.abhaId,
|
||||||
|
data.userImageURL,
|
||||||
|
data.location?.toString(),
|
||||||
|
data.reportUploadTime ?: "",
|
||||||
|
data.testType ?: "",
|
||||||
|
data.testTime ?: "",
|
||||||
|
data.testStatus?.toString() ?: "",
|
||||||
|
data.gender,
|
||||||
|
data.localFlag.toString(),
|
||||||
|
data.deviceId ?: "",
|
||||||
|
data.appVersion ?: "",
|
||||||
|
data.deviceSerialNumber,
|
||||||
|
data.deviceType,
|
||||||
|
data.kitSerial,
|
||||||
|
data.resultData,
|
||||||
|
data.led1Buffer?.toString() ?: "",
|
||||||
|
data.led2Buffer?.toString() ?: "",
|
||||||
|
data.led3Buffer?.toString() ?: "",
|
||||||
|
data.led4Buffer?.toString() ?: "",
|
||||||
|
data.led1Sample?.toString() ?: "",
|
||||||
|
data.led2Sample?.toString() ?: "",
|
||||||
|
data.led3Sample?.toString() ?: "",
|
||||||
|
data.led4Sample?.toString() ?: "",
|
||||||
|
data.led1Average?.toString() ?: "",
|
||||||
|
data.led2Average?.toString() ?: "",
|
||||||
|
data.led3Average?.toString() ?: "",
|
||||||
|
data.led4Average?.toString() ?: "",
|
||||||
|
data.abs1?.toString() ?: "",
|
||||||
|
data.abs2?.toString() ?: "",
|
||||||
|
data.abs3?.toString() ?: "",
|
||||||
|
data.abs4?.toString() ?: "",
|
||||||
|
data.deviceRatio?.toString() ?: "",
|
||||||
|
data.calculatedRatio?.toString() ?: "",
|
||||||
|
data.predictedDenovixRatio?.toString() ?: "",
|
||||||
|
data.coefficients ?: "",
|
||||||
|
data.classificationResult,
|
||||||
|
data.prdClassification,
|
||||||
|
data.errorMessages,
|
||||||
|
data.batteryLevel,
|
||||||
|
data.batteryCapacity,
|
||||||
|
data.batteryMaxCapacity,
|
||||||
|
data.batteryTemperature,
|
||||||
|
data.batteryVoltage
|
||||||
|
)
|
||||||
|
csvWriter.writeNext(row)
|
||||||
|
}
|
||||||
|
writer.close()
|
||||||
|
return true
|
||||||
|
} catch (e: IOException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getExternalStorageDirectory(): File {
|
||||||
|
val folder = File(Environment.getExternalStorageDirectory(), "HposFolder")
|
||||||
|
|
||||||
|
if (!folder.exists()) {
|
||||||
|
folder.mkdirs()
|
||||||
|
}
|
||||||
|
|
||||||
|
return folder
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,33 +6,7 @@ import java.io.File
|
|||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
class LogFileManager(private val context: Context) {
|
interface LogFileManager {
|
||||||
|
|
||||||
fun createLogFile(): File? {
|
fun createLogFile(): File?
|
||||||
val unixTime = System.currentTimeMillis() / 1000L
|
|
||||||
val logFileName = "hpos_$unixTime.log"
|
|
||||||
|
|
||||||
return try {
|
|
||||||
val process = Runtime.getRuntime().exec("logcat -d -v threadtime -t 1000")
|
|
||||||
val logBuilder = StringBuilder()
|
|
||||||
val input = process.inputStream
|
|
||||||
val bufferedReader = input.bufferedReader()
|
|
||||||
|
|
||||||
bufferedReader.forEachLine { line ->
|
|
||||||
logBuilder.append(line).append("\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
val logContent = logBuilder.toString()
|
|
||||||
|
|
||||||
val file = File(context.filesDir, logFileName)
|
|
||||||
val fileOutputStream = FileOutputStream(file)
|
|
||||||
fileOutputStream.write(logContent.toByteArray())
|
|
||||||
fileOutputStream.close()
|
|
||||||
|
|
||||||
file
|
|
||||||
} catch (e: IOException) {
|
|
||||||
Log.e("LogFileManager", "Error creating log file: ${e.message}")
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.example.hpostesting.domain
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.Log
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileOutputStream
|
||||||
|
import java.io.IOException
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class LogFileManagerImpl @Inject constructor(private val context: Context) : LogFileManager {
|
||||||
|
|
||||||
|
override fun createLogFile(): File? {
|
||||||
|
val unixTime = System.currentTimeMillis() / 1000L
|
||||||
|
val logFileName = "hpos_$unixTime.log"
|
||||||
|
|
||||||
|
return try {
|
||||||
|
val process = Runtime.getRuntime().exec("logcat -d -v threadtime -t 1000")
|
||||||
|
val logBuilder = StringBuilder()
|
||||||
|
val input = process.inputStream
|
||||||
|
val bufferedReader = input.bufferedReader()
|
||||||
|
|
||||||
|
bufferedReader.forEachLine { line ->
|
||||||
|
logBuilder.append(line).append("\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
val logContent = logBuilder.toString()
|
||||||
|
|
||||||
|
val file = File(context.filesDir, logFileName)
|
||||||
|
val fileOutputStream = FileOutputStream(file)
|
||||||
|
fileOutputStream.write(logContent.toByteArray())
|
||||||
|
fileOutputStream.close()
|
||||||
|
|
||||||
|
file
|
||||||
|
} catch (e: IOException) {
|
||||||
|
Log.e("LogFileManager", "Error creating log file: ${e.message}")
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,11 +13,13 @@ import com.example.hpostesting.data.dao.HemoCubeDao
|
|||||||
import com.example.hpostesting.data.dao.MyDatabase
|
import com.example.hpostesting.data.dao.MyDatabase
|
||||||
import com.example.hpostesting.data.dao.UserDao
|
import com.example.hpostesting.data.dao.UserDao
|
||||||
import com.example.hpostesting.data.datasource.LocalFileDataSource
|
import com.example.hpostesting.data.datasource.LocalFileDataSource
|
||||||
|
import com.example.hpostesting.data.datasource.LocalFileDataSourceImpl
|
||||||
import com.example.hpostesting.data.repository.DatabaseRepository
|
import com.example.hpostesting.data.repository.DatabaseRepository
|
||||||
import com.example.hpostesting.data.repository.LocalFileRepository
|
import com.example.hpostesting.data.repository.LocalFileRepository
|
||||||
import com.example.hpostesting.data.repository.Repository
|
import com.example.hpostesting.data.repository.Repository
|
||||||
import com.example.hpostesting.domain.AuthInterceptor
|
import com.example.hpostesting.domain.AuthInterceptor
|
||||||
import com.example.hpostesting.domain.LogFileManager
|
import com.example.hpostesting.domain.LogFileManager
|
||||||
|
import com.example.hpostesting.domain.LogFileManagerImpl
|
||||||
import com.example.hpostesting.domain.SaveRawData
|
import com.example.hpostesting.domain.SaveRawData
|
||||||
import com.example.hpostesting.domain.SaveRawDataTest
|
import com.example.hpostesting.domain.SaveRawDataTest
|
||||||
import com.example.hpostesting.util.PropertyProviderImpl
|
import com.example.hpostesting.util.PropertyProviderImpl
|
||||||
@@ -56,6 +58,7 @@ object AppModule {
|
|||||||
fun provideMyHemo(myDatabase: MyDatabase): HemoCubeDao {
|
fun provideMyHemo(myDatabase: MyDatabase): HemoCubeDao {
|
||||||
return myDatabase.hemoCubeDao()
|
return myDatabase.hemoCubeDao()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideMyHemoCubeBuffer(myDatabase: MyDatabase): HemoCubeBufferDao {
|
fun provideMyHemoCubeBuffer(myDatabase: MyDatabase): HemoCubeBufferDao {
|
||||||
@@ -72,14 +75,14 @@ object AppModule {
|
|||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideSaveRawData(): SaveRawData {
|
fun provideSaveRawData(): SaveRawData {
|
||||||
val repository = LocalFileRepository(LocalFileDataSource())
|
val repository = LocalFileRepository(LocalFileDataSourceImpl())
|
||||||
return SaveRawData(repository)
|
return SaveRawData(repository)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideSaveRawDataTest(): SaveRawDataTest {
|
fun provideSaveRawDataTest(): SaveRawDataTest {
|
||||||
val repository = LocalFileRepository(LocalFileDataSource())
|
val repository = LocalFileRepository(LocalFileDataSourceImpl())
|
||||||
return SaveRawDataTest(repository)
|
return SaveRawDataTest(repository)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,11 +172,11 @@ object AppModule {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideLogFileManager(context: Context): LogFileManager = LogFileManager(context)
|
fun provideLogFileManager(context: Context): LogFileManager = LogFileManagerImpl(context)
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideLocalFileDataSource(): LocalFileDataSource {
|
fun provideLocalFileDataSource(): LocalFileDataSource {
|
||||||
return LocalFileDataSource()
|
return LocalFileDataSourceImpl()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,10 +30,10 @@ class CalibrationViewModel @Inject constructor(
|
|||||||
private val sharedPreference: SharedPreferences =
|
private val sharedPreference: SharedPreferences =
|
||||||
context.getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
|
context.getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
|
||||||
|
|
||||||
private val _networkStatusLiveData = NetworkStatusLiveData(context)
|
// private val _networkStatusLiveData = NetworkStatusLiveData(context)
|
||||||
val deviceData = MutableLiveData<DeviceData?>()
|
val deviceData = MutableLiveData<DeviceData?>()
|
||||||
val networkStatusLiveData: LiveData<Boolean>
|
// val networkStatusLiveData: LiveData<Boolean>
|
||||||
get() = _networkStatusLiveData
|
// get() = _networkStatusLiveData
|
||||||
val fireBaseUpload = MutableLiveData<String>()
|
val fireBaseUpload = MutableLiveData<String>()
|
||||||
val savedCalibrationData = MutableLiveData<String>()
|
val savedCalibrationData = MutableLiveData<String>()
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
val progressBar = MutableLiveData(false)
|
val progressBar = MutableLiveData(false)
|
||||||
private val testDetails = DataHolder.selectedTest?.toHemoCubeTestData()
|
private val testDetails = DataHolder.selectedTest?.toHemoCubeTestData()
|
||||||
val messages = MutableLiveData<String>()
|
val messages = MutableLiveData<String>()
|
||||||
private val sharedPreference: SharedPreferences =
|
private val sharedPreference =
|
||||||
context.getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
|
context.getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
|
||||||
|
|
||||||
private val workManager = WorkManager.getInstance(context)
|
private val workManager = WorkManager.getInstance(context)
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package com.example.hpostesting
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
||||||
|
import androidx.lifecycle.Observer
|
||||||
|
import com.example.hpostesting.data.NetworkStatusLiveData
|
||||||
|
import com.example.hpostesting.data.dao.HemoCubeDao
|
||||||
|
import com.example.hpostesting.data.model.Response
|
||||||
|
import com.example.hpostesting.data.model.diagnostics.DiagnosticsData
|
||||||
|
import com.example.hpostesting.data.model.patient.DeviceData
|
||||||
|
import com.example.hpostesting.data.repository.Repository
|
||||||
|
import com.example.hpostesting.presentation.autodac.AutoDacViewModel
|
||||||
|
import io.mockk.*
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import kotlinx.coroutines.test.TestCoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.test.setMain
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
@ExperimentalCoroutinesApi
|
||||||
|
class AutoDacViewModelTest {
|
||||||
|
//
|
||||||
|
// @get:Rule
|
||||||
|
// val instantTaskExecutorRule = InstantTaskExecutorRule()
|
||||||
|
//
|
||||||
|
// private lateinit var viewModel: AutoDacViewModel
|
||||||
|
// private val hemoCubeDao = mockk<HemoCubeDao>()
|
||||||
|
// private val repository = mockk<Repository>()
|
||||||
|
// private val context = mockk<Context>()
|
||||||
|
// private val sharedPreferences = mockk<SharedPreferences>()
|
||||||
|
// private val networkStatusLiveData = mockk<NetworkStatusLiveData>()
|
||||||
|
//
|
||||||
|
// @Before
|
||||||
|
// fun setup() {
|
||||||
|
// MockKAnnotations.init(this)
|
||||||
|
// // Mocking the Context and its dependencies
|
||||||
|
// every { context.applicationContext } returns context
|
||||||
|
// every { context.getSharedPreferences(any(), any()) } returns sharedPreferences
|
||||||
|
// every { context.getSystemService(any()) } returns networkStatusLiveData
|
||||||
|
//
|
||||||
|
// // Mocking the NetworkStatusLiveData
|
||||||
|
// every { networkStatusLiveData.observe(any(), any()) } just Runs
|
||||||
|
//
|
||||||
|
// every { hemoCubeDao.getAll() } returns mockk()
|
||||||
|
// every { repository.addDiagnostics(any()) } returns Response.Success(Unit)
|
||||||
|
//
|
||||||
|
// viewModel = AutoDacViewModel(hemoCubeDao, repository, context)
|
||||||
|
//
|
||||||
|
// Dispatchers.setMain(TestCoroutineDispatcher())
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Test
|
||||||
|
// fun `test addAutoDacDataToDb success`() = runBlocking {
|
||||||
|
// // Given
|
||||||
|
// val diagnosticsData = mockk<DiagnosticsData>()
|
||||||
|
//
|
||||||
|
// // When
|
||||||
|
// viewModel.addAutoDacDataToDb(diagnosticsData)
|
||||||
|
//
|
||||||
|
// // Then
|
||||||
|
// assert(viewModel.fireBaseUpload.value == "Success")
|
||||||
|
// }
|
||||||
|
|
||||||
|
// @Test
|
||||||
|
// fun `test addAutoDacDataToDb error`() = runBlocking {
|
||||||
|
// // Given
|
||||||
|
// every { repository.addDiagnostics(any()) } returns Response.Error(Exception("Test error"))
|
||||||
|
//
|
||||||
|
// // When
|
||||||
|
// viewModel.addAutoDacDataToDb(mockk())
|
||||||
|
//
|
||||||
|
// // Then
|
||||||
|
// assert(viewModel.fireBaseUpload.value == "Error")
|
||||||
|
// }
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
package com.example.hpostesting
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
||||||
|
import com.example.hpostesting.data.model.calibration.CalibrationData
|
||||||
|
import com.example.hpostesting.data.repository.Repository
|
||||||
|
import com.example.hpostesting.presentation.calibration.CalibrationViewModel
|
||||||
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
import org.mockito.ArgumentMatchers.any
|
||||||
|
import org.mockito.Mock
|
||||||
|
import org.mockito.Mockito.mock
|
||||||
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.mockito.MockitoAnnotations
|
||||||
|
|
||||||
|
@ExperimentalCoroutinesApi
|
||||||
|
class CalibrationViewModelTest {
|
||||||
|
|
||||||
|
@get:Rule
|
||||||
|
var instantTaskExecutorRule = InstantTaskExecutorRule()
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
lateinit var repository: Repository
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
lateinit var context: Context
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
lateinit var sharedPreference: SharedPreferences
|
||||||
|
|
||||||
|
private lateinit var editorMock: SharedPreferences.Editor
|
||||||
|
|
||||||
|
private lateinit var viewModel: CalibrationViewModel
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setup() {
|
||||||
|
MockitoAnnotations.initMocks(this)
|
||||||
|
|
||||||
|
// Mock context and shared preferences
|
||||||
|
`when`(context.getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)).thenReturn(sharedPreference)
|
||||||
|
|
||||||
|
editorMock = mock(SharedPreferences.Editor::class.java)
|
||||||
|
`when`(sharedPreference.edit()).thenReturn(editorMock)
|
||||||
|
`when`(editorMock.apply()).then { invocation -> null }
|
||||||
|
`when`(editorMock.putString(any(), any())).thenReturn(editorMock)
|
||||||
|
|
||||||
|
// Set up ViewModel with mocked dependencies
|
||||||
|
viewModel = CalibrationViewModel(repository, context)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testLoadSavedCalibrationData() {
|
||||||
|
// Mock SharedPreferences values
|
||||||
|
`when`(sharedPreference.getString("LED1SLOPE", "")).thenReturn("1.0")
|
||||||
|
`when`(sharedPreference.getString("LED1INTERCEPT", "")).thenReturn("2.0")
|
||||||
|
|
||||||
|
// Call the function to be tested
|
||||||
|
val result = viewModel.loadSavedCalibrationData()
|
||||||
|
|
||||||
|
// Verify the result
|
||||||
|
assert(result.led1Slope == 1.0)
|
||||||
|
assert(result.led1Intercept == 2.0)
|
||||||
|
// Verify other properties...
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testSaveCalibration_Success() {
|
||||||
|
val calibrationData = CalibrationData()
|
||||||
|
calibrationData.led1Slope = 1.0
|
||||||
|
calibrationData.led1Intercept = 2.0
|
||||||
|
|
||||||
|
// Call the function to be tested
|
||||||
|
val result = viewModel.saveCalibration(calibrationData)
|
||||||
|
|
||||||
|
// Verify the result
|
||||||
|
assert(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testSaveCalibration_Failure() {
|
||||||
|
val calibrationData = CalibrationData()
|
||||||
|
calibrationData.led1Slope = 1.0
|
||||||
|
calibrationData.led1Intercept = 2.0
|
||||||
|
|
||||||
|
// Mock SharedPreferences edit and apply to throw an exception
|
||||||
|
`when`(editorMock.apply()).thenThrow(RuntimeException("Apply failed"))
|
||||||
|
|
||||||
|
// Call the function to be tested
|
||||||
|
val result = viewModel.saveCalibration(calibrationData)
|
||||||
|
|
||||||
|
// Verify the result
|
||||||
|
assert(!result)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,112 +2,257 @@ package com.example.hpostesting
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
|
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
||||||
|
import androidx.lifecycle.Observer
|
||||||
|
//import androidx.test.core.app.ApplicationProvider
|
||||||
import com.example.hpostesting.data.dao.HemoCubeBufferDao
|
import com.example.hpostesting.data.dao.HemoCubeBufferDao
|
||||||
import com.example.hpostesting.data.dao.HemoCubeDao
|
import com.example.hpostesting.data.dao.HemoCubeDao
|
||||||
import com.example.hpostesting.data.datasource.LocalFileDataSource
|
import com.example.hpostesting.data.datasource.LocalFileDataSource
|
||||||
|
import com.example.hpostesting.data.model.log.UploadLogsResponse
|
||||||
|
import com.example.hpostesting.data.model.login.LoginResponse
|
||||||
import com.example.hpostesting.data.repository.DatabaseRepository
|
import com.example.hpostesting.data.repository.DatabaseRepository
|
||||||
import com.example.hpostesting.data.repository.Repository
|
import com.example.hpostesting.data.repository.Repository
|
||||||
import com.example.hpostesting.domain.LogFileManager
|
import com.example.hpostesting.domain.LogFileManager
|
||||||
import com.example.hpostesting.presentation.hemocube.HemoCubeFragment
|
import com.example.hpostesting.presentation.hemocube.HemoCubeFragment
|
||||||
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
||||||
import com.example.hpostesting.presentation.hemocube.HemocubeActivity
|
import com.example.hpostesting.presentation.hemocube.HemocubeActivity
|
||||||
|
import com.example.hpostesting.util.TestCoroutineRule
|
||||||
|
import com.google.common.base.Verify.verify
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
|
import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
|
||||||
|
import io.mockk.MockKAnnotations
|
||||||
|
import io.mockk.coEvery
|
||||||
|
import io.mockk.coVerify
|
||||||
|
import io.mockk.every
|
||||||
|
import io.mockk.impl.annotations.MockK
|
||||||
|
import io.mockk.mockk
|
||||||
|
import io.mockk.verify
|
||||||
import junit.framework.TestCase.assertEquals
|
import junit.framework.TestCase.assertEquals
|
||||||
|
import kotlinx.coroutines.test.runBlockingTest
|
||||||
|
import org.junit.After
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
import org.mockito.ArgumentMatchers
|
||||||
|
import org.mockito.ArgumentMatchers.any
|
||||||
import org.mockito.ArgumentMatchers.anyString
|
import org.mockito.ArgumentMatchers.anyString
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
|
import org.mockito.Mockito
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
import org.mockito.MockitoAnnotations
|
import org.mockito.MockitoAnnotations
|
||||||
|
import java.io.File
|
||||||
|
import com.example.hpostesting.data.Result
|
||||||
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
|
import androidx.work.Configuration
|
||||||
|
//import androidx.work.testing.TestListenableWorkerBuilder
|
||||||
|
|
||||||
|
|
||||||
|
@ExperimentalCoroutinesApi
|
||||||
class HemocubeViewModelTest {
|
class HemocubeViewModelTest {
|
||||||
@Mock
|
// @Mock
|
||||||
private lateinit var mockSharedPreferences: SharedPreferences
|
// private lateinit var mockSharedPreferences: SharedPreferences
|
||||||
|
//
|
||||||
@Mock
|
// @Mock
|
||||||
private lateinit var mockActivity: HemocubeActivity // Replace with your actual Activity class
|
// private lateinit var mockActivity: HemocubeActivity // Replace with your actual Activity class
|
||||||
|
//
|
||||||
@Mock
|
// @Mock
|
||||||
private lateinit var mockBinding: FragmentHemoCubeReferenceBinding // Replace with your actual Binding class
|
// private lateinit var mockBinding: FragmentHemoCubeReferenceBinding // Replace with your actual Binding class
|
||||||
|
//
|
||||||
@Mock
|
// @Mock
|
||||||
private lateinit var mockContext: Context
|
// private lateinit var mockContext: Context
|
||||||
|
//
|
||||||
@Mock
|
// @Mock
|
||||||
private lateinit var hemoCubeDaoMock: HemoCubeDao
|
// private lateinit var hemoCubeDaoMock: HemoCubeDao
|
||||||
|
//
|
||||||
@Mock
|
// @Mock
|
||||||
private lateinit var mockRepository: Repository
|
// private lateinit var mockRepository: Repository
|
||||||
|
//
|
||||||
@Mock
|
// @Mock
|
||||||
private lateinit var mockHemoCubeBufferDao: HemoCubeBufferDao
|
// private lateinit var mockHemoCubeBufferDao: HemoCubeBufferDao
|
||||||
|
//
|
||||||
// @Mock
|
// @Mock
|
||||||
// private lateinit var mockLogFileManager: LogFileManager
|
// private lateinit var mockLogFileManager: LogFileManager
|
||||||
//
|
//
|
||||||
// @Mock
|
// @Mock
|
||||||
// private lateinit var mockLocalFileDataSource: LocalFileDataSource
|
// private lateinit var mockLocalFileDataSource: LocalFileDataSource
|
||||||
|
//
|
||||||
private lateinit var hemoCubeFragment: HemoCubeFragment
|
// private lateinit var hemoCubeFragment: HemoCubeFragment
|
||||||
|
//
|
||||||
private lateinit var hemoCubeViewModel: HemoCubeViewModel
|
// private lateinit var hemoCubeViewModel: HemoCubeViewModel
|
||||||
|
//
|
||||||
@Before
|
// @Before
|
||||||
fun setUp() {
|
// fun setUp() {
|
||||||
MockitoAnnotations.openMocks(this)
|
// MockitoAnnotations.openMocks(this)
|
||||||
hemoCubeFragment = HemoCubeFragment()
|
// hemoCubeFragment = HemoCubeFragment()
|
||||||
|
// Mockito.`when`(
|
||||||
|
// mockSharedPreferences.getString(
|
||||||
|
// ArgumentMatchers.anyString(),
|
||||||
|
// ArgumentMatchers.anyString()
|
||||||
|
// )
|
||||||
|
// ).thenReturn("dummy_value")
|
||||||
// hemoCubeViewModel = HemoCubeViewModel(hemoCubeDaoMock, mockHemoCubeBufferDao, mockRepository, mockLogFileManager, mockLocalFileDataSource, mockContext)
|
// 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()
|
// @Test
|
||||||
|
// fun `parseData test`() {
|
||||||
|
// assertEquals(1, 1)
|
||||||
|
// }
|
||||||
//
|
//
|
||||||
// assertEquals("1705429433", hemoCubeViewModel.getCurrentDate())
|
// @Test
|
||||||
}
|
// fun `getCurrentDate returns date`() {
|
||||||
|
//// `when`(hemoCubeViewModel.getCurrentDate()).thenReturn("1705429433")
|
||||||
|
////
|
||||||
|
//// val result = hemoCubeViewModel.getCurrentDate()
|
||||||
|
////
|
||||||
|
//// assertEquals("1705429433", hemoCubeViewModel.getCurrentDate())
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Test
|
||||||
|
// fun `extractMiddleString to get device id`() {
|
||||||
|
// // Arrange
|
||||||
|
// `when`(mockSharedPreferences.getString(anyString(), anyString())).thenReturn("dummy_value")
|
||||||
|
//
|
||||||
|
// // Act
|
||||||
|
// val deviceId = hemoCubeFragment.extractMiddleString("SNS HPP1-9000 SNE")
|
||||||
|
//
|
||||||
|
// // Assert
|
||||||
|
// assertEquals("HPP1-9000", deviceId)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @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)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @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)
|
||||||
|
// }
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `extractMiddleString to get device id`() {
|
|
||||||
// Arrange
|
|
||||||
`when`(mockSharedPreferences.getString(anyString(), anyString())).thenReturn("dummy_value")
|
|
||||||
|
|
||||||
// Act
|
|
||||||
val deviceId = hemoCubeFragment.extractMiddleString("SNS HPP1-9000 SNE")
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
assertEquals("HPP1-9000", deviceId)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `updateDeviceId in shared pref`() {
|
|
||||||
// Arrange
|
|
||||||
`when`(mockSharedPreferences.getString(anyString(), anyString())).thenReturn("HPP1-0001")
|
|
||||||
|
|
||||||
// Act
|
// @get:Rule
|
||||||
val deviceId = mockSharedPreferences.getString(anyString(), anyString())
|
// val instantTaskExecutorRule = InstantTaskExecutorRule()
|
||||||
|
//
|
||||||
// Assert
|
// @get:Rule
|
||||||
assertEquals("HPP1-0001", deviceId)
|
// val coroutineRule = TestCoroutineRule()
|
||||||
}
|
//
|
||||||
|
// @MockK(relaxed = true)
|
||||||
@Test
|
// lateinit var repository: Repository
|
||||||
fun `allReadingsComplete check`() {
|
//
|
||||||
// Arrange
|
// @MockK(relaxed = true)
|
||||||
val repeatReadingCount = 1
|
// lateinit var logFileManager: LogFileManager
|
||||||
val readingsPerSample = 1
|
//
|
||||||
|
// @MockK(relaxed = true)
|
||||||
// Act
|
// lateinit var context: Context
|
||||||
val result = hemoCubeFragment.allReadingsComplete(repeatReadingCount, readingsPerSample)
|
//
|
||||||
|
// @MockK(relaxed = true)
|
||||||
// Assert
|
// lateinit var observer: Observer<Result<LoginResponse>>
|
||||||
assertEquals(true, result)
|
//
|
||||||
assertEquals(hemoCubeFragment.allReadingsComplete(0, 1), false)
|
// private lateinit var viewModel: HemoCubeViewModel
|
||||||
}
|
//
|
||||||
|
// @Before
|
||||||
|
// fun setup() {
|
||||||
|
// MockKAnnotations.init(this)
|
||||||
|
//
|
||||||
|
// every { context.getSharedPreferences(any(), any()) } returns mockk()
|
||||||
|
//
|
||||||
|
// viewModel = HemoCubeViewModel(
|
||||||
|
// mockk(),
|
||||||
|
// mockk(),
|
||||||
|
// repository,
|
||||||
|
// logFileManager,
|
||||||
|
// mockk(),
|
||||||
|
// context
|
||||||
|
// )
|
||||||
|
// viewModel.loginResponse.observeForever(observer)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @After
|
||||||
|
// fun teardown() {
|
||||||
|
// viewModel.loginResponse.removeObserver(observer)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Test
|
||||||
|
// fun `login() should update LiveData with success`() = coroutineRule.runBlockingTest {
|
||||||
|
// // Set up WorkManager with TestListenableWorkerBuilder
|
||||||
|
// val config = Configuration.Builder()
|
||||||
|
// .setMinimumLoggingLevel(android.util.Log.DEBUG)
|
||||||
|
// .build()
|
||||||
|
//
|
||||||
|
// val context = ApplicationProvider.getApplicationContext<Context>()
|
||||||
|
//
|
||||||
|
// WorkManagerTestInitHelper.initializeTestWorkManager(context, config)
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// // Arrange
|
||||||
|
// coEvery { repository.login(any()) } returns Result.Success(mockk())
|
||||||
|
//
|
||||||
|
// // Act
|
||||||
|
// viewModel.login(mockk())
|
||||||
|
//
|
||||||
|
// // Assert
|
||||||
|
// coVerify { repository.login(any()) }
|
||||||
|
// verify { observer.onChanged(Result.Success(any())) }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Test
|
||||||
|
// fun `login() should update LiveData with error`() = coroutineRule.runBlockingTest {
|
||||||
|
// // Arrange
|
||||||
|
// coEvery { repository.login(any()) } returns Result.Error(Exception("Login failed"))
|
||||||
|
//
|
||||||
|
// // Act
|
||||||
|
// viewModel.login(mockk())
|
||||||
|
//
|
||||||
|
// // Assert
|
||||||
|
// coVerify { repository.login(any()) }
|
||||||
|
// verify { observer.onChanged(Result.Error(any())) }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Test
|
||||||
|
// fun `uploadLogs() should update LiveData with success`() = coroutineRule.runBlockingTest {
|
||||||
|
// // Arrange
|
||||||
|
// val file = mockk<File>(relaxed = true)
|
||||||
|
// val response = Result.Success(mockk<UploadLogsResponse>())
|
||||||
|
// every { logFileManager.createLogFile() } returns file
|
||||||
|
// coEvery { repository.uploadLogs(any()) } returns response
|
||||||
|
//
|
||||||
|
// // Act
|
||||||
|
// viewModel.uploadLogs()
|
||||||
|
//
|
||||||
|
// // Assert
|
||||||
|
// verify { observer.onChanged(response) }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Test
|
||||||
|
// fun `uploadLogs() should update LiveData with error`() = coroutineRule.runBlockingTest {
|
||||||
|
// // Arrange
|
||||||
|
// val file = mockk<File>(relaxed = true)
|
||||||
|
// val response = Result.Error(Exception("Upload failed"))
|
||||||
|
// every { logFileManager.createLogFile() } returns file
|
||||||
|
// coEvery { repository.uploadLogs(any()) } returns response
|
||||||
|
//
|
||||||
|
// // Act
|
||||||
|
// viewModel.uploadLogs()
|
||||||
|
//
|
||||||
|
// // Assert
|
||||||
|
// verify { observer.onChanged(response) }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user