mirror of
https://github.com/pcvolkmer/onco-analytics-monitor.git
synced 2025-04-19 19:16:52 +00:00
test: add tests for InMemoryConditionRepository
This commit is contained in:
parent
b07675fabb
commit
afa9be27b9
@ -42,8 +42,7 @@ class InMemoryConditionRepository : ConditionRepository {
|
|||||||
|
|
||||||
override fun saveIfNewerVersion(condition: Condition): Boolean {
|
override fun saveIfNewerVersion(condition: Condition): Boolean {
|
||||||
if ((this.conditions[condition.id]?.version ?: 0) < condition.version) {
|
if ((this.conditions[condition.id]?.version ?: 0) < condition.version) {
|
||||||
this.conditions[condition.id] = condition
|
return this.save(condition)
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,47 @@
|
|||||||
|
package dev.pcvolkmer.oncoanalytics.monitor.conditions
|
||||||
|
|
||||||
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
|
import org.junit.jupiter.api.BeforeEach
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
class InMemoryConditionRepositoryTest {
|
||||||
|
|
||||||
|
private lateinit var conditionsRepository: InMemoryConditionRepository
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
fun setup() {
|
||||||
|
this.conditionsRepository = InMemoryConditionRepository()
|
||||||
|
|
||||||
|
// Setup initial data
|
||||||
|
this.conditionsRepository.saveIfNewerVersion(Condition(ConditionId("TEST"), "F79.9", 2))
|
||||||
|
assertThat(this.conditionsRepository.findAll()).hasSize(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun shouldSaveNewerCondition() {
|
||||||
|
val success = this.conditionsRepository.saveIfNewerVersion(Condition(ConditionId("TEST"), "F79.9", 3))
|
||||||
|
|
||||||
|
assertThat(success).isTrue
|
||||||
|
assertThat(this.conditionsRepository.findAll()).hasSize(1)
|
||||||
|
assertThat(this.conditionsRepository.findAll()[0].version).isEqualTo(3)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun shouldNotSaveSameConditionTwice() {
|
||||||
|
val success = this.conditionsRepository.saveIfNewerVersion(Condition(ConditionId("TEST"), "F79.9", 2))
|
||||||
|
|
||||||
|
assertThat(success).isFalse
|
||||||
|
assertThat(this.conditionsRepository.findAll()).hasSize(1)
|
||||||
|
assertThat(this.conditionsRepository.findAll()[0].version).isEqualTo(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun shouldNotSaveOlderCondition() {
|
||||||
|
val success = this.conditionsRepository.saveIfNewerVersion(Condition(ConditionId("TEST"), "F79.9", 1))
|
||||||
|
|
||||||
|
assertThat(success).isFalse
|
||||||
|
assertThat(this.conditionsRepository.findAll()).hasSize(1)
|
||||||
|
assertThat(this.conditionsRepository.findAll()[0].version).isEqualTo(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user