package dev.fyloz.trial.colorrecipesexplorer.service

import com.nhaarman.mockitokotlin2.doReturn
import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.spy
import com.nhaarman.mockitokotlin2.whenever
import dev.fyloz.trial.colorrecipesexplorer.model.Material
import dev.fyloz.trial.colorrecipesexplorer.model.MixMaterial
import dev.fyloz.trial.colorrecipesexplorer.model.material
import dev.fyloz.trial.colorrecipesexplorer.model.mixMaterial
import dev.fyloz.trial.colorrecipesexplorer.repository.MixMaterialRepository
import org.junit.jupiter.api.Nested
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class MixMaterialServiceTest : AbstractModelServiceTest<MixMaterial, MixMaterialService, MixMaterialRepository>() {
    override val repository: MixMaterialRepository = mock()
    override val service: MixMaterialService = spy(MixMaterialServiceImpl(repository))

    private val material: Material = material(id = 0L)
    override val entity: MixMaterial = mixMaterial(id = 0L, material = material)
    override val anotherEntity: MixMaterial = mixMaterial(id = 1L, material = material)

    @Nested
    inner class ExistsByMaterial {
        fun `returns true when a mix material with the given material exists`() {
            whenever(repository.existsByMaterial(material)).doReturn(true)

            val found = service.existsByMaterial(material)

            assertTrue(found)
        }

        fun `returns false when no mix material with the given material exists`() {
            whenever(repository.existsByMaterial(material)).doReturn(false)

            val found = service.existsByMaterial(material)

            assertFalse(found)
        }
    }
}
