package dev.fyloz.plannervio.core.service

import io.mockk.clearAllMocks
import io.mockk.every
import io.mockk.mockk
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import java.util.*
import kotlin.test.assertEquals

class I18nServiceTest {
    private val specificBundle: ResourceBundle = mockk()
    private val keywordsBundle: ResourceBundle = mockk()

    private val service: II18nService = I18nService(specificBundle, keywordsBundle)

    @BeforeEach
    fun setUp() {
        clearAllMocks()
    }

    @Nested
    inner class GetLocalizedString {
        @Test
        fun `contains specific bundle`() {
            val key = iI18nKeyFactory("specific")
            val value = "specific value"
            every { specificBundle.containsKey(key.keyName) } returns true
            every { specificBundle.getObject(key.keyName) } returns value
            every { keywordsBundle.containsKey(key.keyName) } returns false

            val found = service.getLocalizedString(key)

            assertEquals(value, found)
        }

        @Test
        fun `contains keywords bundle`() {
            val key = iI18nKeyFactory("keyword")
            val value = "keyword value"
            every { keywordsBundle.containsKey(key.keyName) } returns true
            every { keywordsBundle.getObject(key.keyName) } returns value
            every { specificBundle.containsKey(key.keyName) } returns false

            val found = service.getLocalizedString(key)

            assertEquals(value, found)
        }
    }
}
