package com.github.nullptroma.wallenc.domain.errors

import org.junit.Assert.assertSame
import org.junit.Assert.assertTrue
import org.junit.Test
import java.io.FileNotFoundException
import java.io.IOException

class WallencExceptionMappingTest {

    @Test
    fun preservesWallencException() {
        val original = WallencException.Feature.StorageNotFound()
        assertSame(original, original.toWallencException())
    }

    @Test
    fun mapsFileNotFoundException() {
        val mapped = FileNotFoundException("missing").toWallencException()
        assertTrue(mapped is WallencException.Storage.FileNotFound)
    }

    @Test
    fun mapsIOExceptionToIoFailed() {
        val cause = IOException("disk")
        val mapped = cause.toWallencException()
        assertTrue(mapped is WallencException.Network.IoFailed)
        assertSame(cause, (mapped as WallencException.Network.IoFailed).cause)
    }

    @Test
    fun mapsGenericExceptionToUnknown() {
        val cause = Exception("boom")
        val mapped = cause.toWallencException()
        assertTrue(mapped is WallencException.Unknown)
        assertSame(cause, (mapped as WallencException.Unknown).cause)
    }
}
