How to write a testable code
Published:
Why We Need Unit Testing!
let’s see this snippet of code
fun invalidateCache(users: List<User>) {
val userIds=users.map{it.userId}
getDBUsers().forEach { user ->
if (user.userId == null) {
//invalid data
DatabaseManager.deleteAllUsers()
return
} else (!usersIds.contains(user.userId))
DatabaseManager.deleteUserById(it.userId)
}
}