package de.arxsilex.maptools.converter.desktop

import de.arxsilex.maptools.converter.core.MapsforgeProcessorType
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull

class MapsforgeFallbackProcessorTest {
    @Test
    fun `retries a ram heap exhaustion with disk processing`() {
        assertEquals(
            MapsforgeProcessorType.HD,
            mapsforgeFallbackProcessor(
                primaryProcessor = MapsforgeProcessorType.RAM,
                failureLog = "java.lang.OutOfMemoryError: Java heap space",
                allowRamFallback = true,
            ),
        )
    }

    @Test
    fun `retries the known hd store finalization failure only for regular pbf input`() {
        val log = "Cannot begin reading in Add stage, must call complete first."
        assertEquals(
            MapsforgeProcessorType.RAM,
            mapsforgeFallbackProcessor(MapsforgeProcessorType.HD, log, allowRamFallback = true),
        )
        assertNull(mapsforgeFallbackProcessor(MapsforgeProcessorType.HD, log, allowRamFallback = false))
    }

    @Test
    fun `does not hide unrelated writer failures`() {
        assertNull(
            mapsforgeFallbackProcessor(
                primaryProcessor = MapsforgeProcessorType.RAM,
                failureLog = "Ungültige Bounding Box",
                allowRamFallback = true,
            ),
        )
    }
}
