<commit_before>package jp.toastkid.article_viewer.article.detail

import android.widget.TextView
import io.mockk.MockKAnnotations
import io.mockk.Runs
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.impl.annotations.InjectMockKs
import io.mockk.impl.annotations.MockK
import io.mockk.just
import io.mockk.unmockkAll
import io.noties.markwon.Markwon
import jp.toastkid.article_viewer.article.ArticleRepository
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.test.runBlockingTest
import org.junit.After
import org.junit.Before
import org.junit.Test

/**
 * @author toastkidjp
 */
class ContentLoaderUseCaseTest {

    @InjectMockKs
    private lateinit var contentLoaderUseCase: ContentLoaderUseCase

    @MockK
    private lateinit var repository: ArticleRepository

    @MockK
    private lateinit var markwon: Markwon

    @MockK
    private lateinit var contentView: TextView

    @MockK
    private lateinit var subheads: MutableList<String>

    @MockK
    private lateinit var linkGeneratorService: LinkGeneratorService

    @Suppress("unused")
    private val mainDispatcher: CoroutineDispatcher = Dispatchers.Unconfined

    @Suppress("unused")
    private val ioDispatcher: CoroutineDispatcher = Dispatchers.Unconfined

    @Suppress("unused")
    private val defaultDispatcher: CoroutineDispatcher = Dispatchers.Unconfined

    @Before
    fun setUp() {
        MockKAnnotations.init(this)

        coEvery { markwon.setMarkdown(any(), any()) }.just(Runs)
        coEvery { linkGeneratorService.invoke(any()) }.just(Runs)
    }

    @Test
    fun test() = runBlockingTest {
        coEvery { repository.findContentByTitle(any()) }.returns("test")

        contentLoaderUseCase.invoke("test")

        coVerify(exactly = 1) { repository.findContentByTitle(any()) }
        coVerify(exactly = 1) { markwon.setMarkdown(any(), any()) }
        coVerify(exactly = 1) { linkGeneratorService.invoke(any()) }
    }

    @Test
    fun testContentIsNull() = runBlockingTest {
        coEvery { repository.findContentByTitle(any()) }.returns(null)

        contentLoaderUseCase.invoke("test")
        coVerify(exactly = 1) { repository.findContentByTitle(any()) }
        coVerify(exactly = 0) { markwon.setMarkdown(any(), any()) }
        coVerify(exactly = 0) { linkGeneratorService.invoke(any()) }
    }

    @After
    fun tearDown() {
        unmockkAll()
    }

}<commit_msg>refactor #485 Remove useless runBlockingTest.<commit_after>package jp.toastkid.article_viewer.article.detail

import android.widget.TextView
import io.mockk.MockKAnnotations
import io.mockk.Runs
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.impl.annotations.InjectMockKs
import io.mockk.impl.annotations.MockK
import io.mockk.just
import io.mockk.unmockkAll
import io.noties.markwon.Markwon
import jp.toastkid.article_viewer.article.ArticleRepository
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import org.junit.After
import org.junit.Before
import org.junit.Test

/**
 * @author toastkidjp
 */
class ContentLoaderUseCaseTest {

    @InjectMockKs
    private lateinit var contentLoaderUseCase: ContentLoaderUseCase

    @MockK
    private lateinit var repository: ArticleRepository

    @MockK
    private lateinit var markwon: Markwon

    @MockK
    private lateinit var contentView: TextView

    @MockK
    private lateinit var subheads: MutableList<String>

    @MockK
    private lateinit var linkGeneratorService: LinkGeneratorService

    @Suppress("unused")
    private val mainDispatcher: CoroutineDispatcher = Dispatchers.Unconfined

    @Suppress("unused")
    private val ioDispatcher: CoroutineDispatcher = Dispatchers.Unconfined

    @Suppress("unused")
    private val defaultDispatcher: CoroutineDispatcher = Dispatchers.Unconfined

    @Before
    fun setUp() {
        MockKAnnotations.init(this)

        coEvery { markwon.setMarkdown(any(), any()) }.just(Runs)
        coEvery { linkGeneratorService.invoke(any()) }.just(Runs)
    }

    @Test
    fun test() {
        coEvery { repository.findContentByTitle(any()) }.returns("test")

        contentLoaderUseCase.invoke("test")

        coVerify(exactly = 1) { repository.findContentByTitle(any()) }
        coVerify(exactly = 1) { markwon.setMarkdown(any(), any()) }
        coVerify(exactly = 1) { linkGeneratorService.invoke(any()) }
    }

    @Test
    fun testContentIsNull() {
        coEvery { repository.findContentByTitle(any()) }.returns(null)

        contentLoaderUseCase.invoke("test")
        coVerify(exactly = 1) { repository.findContentByTitle(any()) }
        coVerify(exactly = 0) { markwon.setMarkdown(any(), any()) }
        coVerify(exactly = 0) { linkGeneratorService.invoke(any()) }
    }

    @After
    fun tearDown() {
        unmockkAll()
    }

}
{'fraction_non_alphanumeric': 0.09969167523124357, 'fraction_numerical': 0.003083247687564234, 'mean_word_length': 3.8225966303270567, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6444742', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1487, 'n_words': 290}