package kr.co.vividnext.sodalive.content import kr.co.vividnext.sodalive.i18n.translation.SourceTextNormalizer import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import org.mockito.Mockito class LanguageDetectionCacheServiceTest { @Test fun shouldReuseCachedLanguageDetectionForSameNormalizedText() { val repository = Mockito.mock(LanguageDetectionResultRepository::class.java) val service = LanguageDetectionCacheService(repository) val sourceHash = SourceTextNormalizer.hash("Hello world") Mockito.`when`( repository.findBySourceHashAndProviderAndNormalizationVersion( sourceHash = sourceHash, provider = "papago", normalizationVersion = SourceTextNormalizer.NORMALIZATION_VERSION ) ).thenReturn( LanguageDetectionResult( sourceHash = sourceHash, sourceTextSample = "Hello world", detectedLanguage = "en", provider = "papago", confidence = null, normalizationVersion = SourceTextNormalizer.NORMALIZATION_VERSION ) ) var providerCalls = 0 val detected = service.detectWithCache("Hello world") { providerCalls++ "ko" } assertEquals("en", detected) assertEquals(0, providerCalls) Mockito.verify(repository, Mockito.never()).save(Mockito.any(LanguageDetectionResult::class.java)) } }