package eu.gaudian.translator.utils

import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestDispatcher
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import org.junit.rules.TestWatcher
import org.junit.runner.Description

/**
 * Test rule for setting up coroutine testing environment
 */
class CoroutineTestRule @OptIn(ExperimentalCoroutinesApi::class) constructor(
    val testDispatcher: TestDispatcher = UnconfinedTestDispatcher()
) : TestWatcher() {
    
    lateinit var testScope: TestScope
        private set

    override fun starting(description: Description) {
        super.starting(description)
        testScope = TestScope(testDispatcher)
    }
}

/**
 * Base test class for API architecture tests
 */
abstract class BaseApiTest {
    
    @get:org.junit.Rule
    val coroutineRule = CoroutineTestRule()
    
    protected val testDispatcher = coroutineRule.testDispatcher
    protected val testScope = coroutineRule.testScope
}
