Remove gunzip dependency from tests
Change-Id: I411ccdd0368878cd486e14b16646d95d823e2787
diff --git a/app/src/test/kotlin/de/ids_mannheim/korapxmltools/KrillJsonGeneratorTest.kt b/app/src/test/kotlin/de/ids_mannheim/korapxmltools/KrillJsonGeneratorTest.kt
index cdad437..a23aa67 100644
--- a/app/src/test/kotlin/de/ids_mannheim/korapxmltools/KrillJsonGeneratorTest.kt
+++ b/app/src/test/kotlin/de/ids_mannheim/korapxmltools/KrillJsonGeneratorTest.kt
@@ -7,6 +7,7 @@
import java.io.File
import java.io.PrintStream
import java.net.URL
+import java.util.zip.GZIPInputStream
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
@@ -62,10 +63,7 @@
assertTrue(jsonFiles.isNotEmpty(), "No JSON files found in ${tarFile.path}")
jsonFiles.associate { jsonFile ->
- val jsonContent = ProcessBuilder("gunzip", "-c", jsonFile.path)
- .redirectOutput(ProcessBuilder.Redirect.PIPE)
- .start()
- .inputStream
+ val jsonContent = GZIPInputStream(jsonFile.inputStream())
.bufferedReader()
.use { it.readText() }
jsonFile.name.removeSuffix(".gz") to jsonContent
@@ -184,9 +182,8 @@
assertTrue(jsonFiles.isNotEmpty())
jsonFiles.forEach { jsonFile ->
- val jsonContent = ProcessBuilder("gunzip", "-c", jsonFile.path)
- .redirectOutput(ProcessBuilder.Redirect.PIPE)
- .start().inputStream.bufferedReader().readText()
+ val jsonContent = GZIPInputStream(jsonFile.inputStream())
+ .bufferedReader().readText()
// Check for required fields in the JSON output
assertTrue(jsonContent.contains("\"@context\""))
@@ -223,9 +220,8 @@
assertTrue(jsonFiles.isNotEmpty())
jsonFiles.forEach { jsonFile ->
- val jsonContent = ProcessBuilder("gunzip", "-c", jsonFile.path)
- .redirectOutput(ProcessBuilder.Redirect.PIPE)
- .start().inputStream.bufferedReader().readText()
+ val jsonContent = GZIPInputStream(jsonFile.inputStream())
+ .bufferedReader().readText()
assertTrue(
jsonContent.contains("<:") && jsonContent.contains("/d:"),
@@ -254,9 +250,8 @@
assertTrue(jsonFiles.isNotEmpty())
jsonFiles.forEach { jsonFile ->
- val jsonContent = ProcessBuilder("gunzip", "-c", jsonFile.path)
- .redirectOutput(ProcessBuilder.Redirect.PIPE)
- .start().inputStream.bufferedReader().readText()
+ val jsonContent = GZIPInputStream(jsonFile.inputStream())
+ .bufferedReader().readText()
assertTrue(jsonContent.contains("base/s:t"), "JSON should contain base text span (base/s:t)")
assertTrue(jsonContent.contains("base/s:s"), "JSON should contain base sentence spans (base/s:s)")
@@ -286,9 +281,8 @@
assertTrue(jsonFiles.isNotEmpty())
jsonFiles.forEach { jsonFile ->
- val jsonContent = ProcessBuilder("gunzip", "-c", jsonFile.path)
- .redirectOutput(ProcessBuilder.Redirect.PIPE)
- .start().inputStream.bufferedReader().readText()
+ val jsonContent = GZIPInputStream(jsonFile.inputStream())
+ .bufferedReader().readText()
val foundries = jsonContent.substringAfter("\"foundries\":").substringBefore(",").trim()
assertTrue(foundries.contains("spacy"))
@@ -463,9 +457,8 @@
// Verify we can read each JSON
jsonFiles.forEach { jsonFile ->
- val jsonContent = ProcessBuilder("gunzip", "-c", jsonFile.path)
- .redirectOutput(ProcessBuilder.Redirect.PIPE)
- .start().inputStream.bufferedReader().readText()
+ val jsonContent = GZIPInputStream(jsonFile.inputStream())
+ .bufferedReader().readText()
assertTrue(jsonContent.contains("\"@type\":\"koral:corpus\""),
"Each JSON should be a valid Krill corpus document")