From b07675fabbd9858b3cec7c5f3a877c48e404c218 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Wed, 7 Aug 2024 20:44:26 +0200 Subject: [PATCH] test: add tests for helpers --- build.gradle.kts | 1 + .../oncoanalytics/monitor/HelpersTest.kt | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/test/kotlin/dev/pcvolkmer/oncoanalytics/monitor/HelpersTest.kt diff --git a/build.gradle.kts b/build.gradle.kts index dbc9f41..561b759 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -44,6 +44,7 @@ dependencies { testImplementation("org.jetbrains.kotlin:kotlin-test-junit5") testImplementation("org.springframework.integration:spring-integration-test") testImplementation("org.springframework.kafka:spring-kafka-test") + testImplementation("org.mockito.kotlin:mockito-kotlin:5.4.0") testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/src/test/kotlin/dev/pcvolkmer/oncoanalytics/monitor/HelpersTest.kt b/src/test/kotlin/dev/pcvolkmer/oncoanalytics/monitor/HelpersTest.kt new file mode 100644 index 0000000..9303880 --- /dev/null +++ b/src/test/kotlin/dev/pcvolkmer/oncoanalytics/monitor/HelpersTest.kt @@ -0,0 +1,59 @@ +package dev.pcvolkmer.oncoanalytics.monitor + +import dev.pcvolkmer.oncoanalytics.monitor.conditions.Condition +import dev.pcvolkmer.oncoanalytics.monitor.conditions.ConditionId +import dev.pcvolkmer.oncoanalytics.monitor.conditions.ConditionRepository +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.Mock +import org.mockito.junit.jupiter.MockitoExtension +import org.mockito.kotlin.whenever + +@ExtendWith(MockitoExtension::class) +class HelpersTest { + + private lateinit var conditionsRepository: ConditionRepository + + @BeforeEach + fun setup( + @Mock conditionRepository: ConditionRepository + ) { + this.conditionsRepository = conditionRepository + } + + @Test + fun statisticsContainAllRequiredKeys() { + val actual = fetchStatistics("test", this.conditionsRepository).entries.map { it.name } + + assertThat(actual).isEqualTo(allKeys) + } + + @Test + fun correctStatistics() { + whenever(this.conditionsRepository.findAll()).thenReturn(conditionForEachKey) + + val actual = fetchStatistics("test", this.conditionsRepository) + + actual.entries.forEach { entry -> + assertThat(entry.count).isEqualTo(1) + } + } + + companion object { + val conditionForEachKey = allKeys + .map { key -> key.split("[,\\-]".toRegex()).first().toString() } + .map { key -> + if (key == "Other" || key.contains('.', true)) { + key + } else { + "$key.9" + } + } + .map { icd10 -> + Condition(ConditionId("TEST$icd10"), icd10, 1) + } + } + +} \ No newline at end of file