summaryrefslogtreecommitdiff
path: root/src/test/kotlin
diff options
context:
space:
mode:
authorPaul-Christian Volkmer2025-11-20 12:52:26 +0100
committerGitHub2025-11-20 12:52:26 +0100
commit86fc3e361c9c5e290319a0c049ef0c6c0a0764ad (patch)
treee48cb9762c2419b6b0436d653c12f0bfc28db7d2 /src/test/kotlin
parentab2c0a3cec3cd8ed04de90ac74cb4bfdbaa010e5 (diff)
fix: possible NPE for MSI anonymization (#195)
This might occur if a null value is present in the list of MSI findings. With this change, the usage if "it" has been replaced with proper element names.
Diffstat (limited to 'src/test/kotlin')
-rw-r--r--src/test/kotlin/dev/dnpm/etl/processor/pseudonym/ExtensionsTest.kt41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/test/kotlin/dev/dnpm/etl/processor/pseudonym/ExtensionsTest.kt b/src/test/kotlin/dev/dnpm/etl/processor/pseudonym/ExtensionsTest.kt
index a0b3b24..2b4cd34 100644
--- a/src/test/kotlin/dev/dnpm/etl/processor/pseudonym/ExtensionsTest.kt
+++ b/src/test/kotlin/dev/dnpm/etl/processor/pseudonym/ExtensionsTest.kt
@@ -250,4 +250,45 @@ class ExtensionsTest {
.isEqualTo(mtbFile.guidelineProcedures.first().reason.id)
assertThat(mtbFile.diagnoses.first().id).isEqualTo(mtbFile.specimens.first().diagnosis.id)
}
+
+ @Test
+ fun shouldNotThrowAnyExceptionOnMissingMsiId(
+ @Mock pseudonymizeService: PseudonymizeService
+ ) {
+
+ doAnswer {
+ it.arguments[0]
+ "PSEUDO-ID"
+ }
+ .whenever(pseudonymizeService)
+ .patientPseudonym(anyValueClass())
+
+ doAnswer { "TESTDOMAIN" }.whenever(pseudonymizeService).prefix()
+
+ val mtbFile =
+ Mtb().apply {
+ this.patient =
+ Patient().apply {
+ this.id = "PID"
+ this.birthDate = Date.from(Instant.now())
+ this.gender = GenderCoding().apply { this.code = GenderCodingCode.MALE }
+ }
+ this.msiFindings = listOf(
+ null,
+ Msi.builder().id("1").build(),
+ Msi.builder(). build(),
+ Msi.builder().specimen(null).build(),
+ Msi.builder().specimen(Reference.builder().build()).build()
+ )
+ }
+
+ mtbFile.pseudonymizeWith(pseudonymizeService)
+ mtbFile.anonymizeContentWith(pseudonymizeService)
+
+ assertThat( mtbFile.msiFindings ).isNotNull
+ assertThat(mtbFile.msiFindings[1]).satisfiesAnyOf(
+ { assertThat(it.id).isNull() },
+ { assertThat(it.id).isEqualTo("TESTDOMAIN44e20a53bbbf9f3ae39626d05df7014dcd77d6098")}
+ )
+ }
}