Coverage Summary for Class: AddCharacterImpl (com.javiersc.samples.strategies.characters)
Class |
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
AddCharacterImpl |
0%
(0/2)
|
0%
(0/4)
|
0%
(0/7)
|
0%
(0/47)
|
AddCharacterImpl$invoke$1 |
|
Total |
0%
(0/2)
|
0%
(0/4)
|
0%
(0/7)
|
0%
(0/47)
|
package com.javiersc.samples.strategies.characters
import com.javiersc.kaari.samples.strategies.internal.KaariDatabase
import kotlin.time.Duration.Companion.milliseconds
import kotlinx.coroutines.delay
interface AddCharacter {
suspend operator fun invoke(character: Character)
}
class AddCharacterImpl(
private val database: KaariDatabase,
) : AddCharacter {
override suspend operator fun invoke(character: Character) {
delay(300.milliseconds)
val hasCharacter =
database.characterQueries.selectById(character.id).executeAsOneOrNull() != null
if (!hasCharacter) {
database.characterQueries.insert(character.id, character.name)
}
}
}