<commit_before>package jp.toastkid.article_viewer.calendar

import io.mockk.MockKAnnotations
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.mockkObject
import io.mockk.verify
import jp.toastkid.article_viewer.article.Article
import jp.toastkid.article_viewer.article.ArticleRepository
import jp.toastkid.lib.ContentViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.setMain
import org.junit.Before
import org.junit.Test

/**
 * @author toastkidjp
 */
class DateSelectedActionServiceTest {

    @MockK
    private lateinit var repository: ArticleRepository

    @MockK
    private lateinit var viewModel: ContentViewModel

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

    @ExperimentalCoroutinesApi
    @Test
    fun test() {
        every { repository.findFirst(any()) }.answers { Article(1).also { it.title = "test" } }
        every { viewModel.newArticle(any()) }.answers { Unit }

        mockkObject(TitleFilterGenerator)
        every { TitleFilterGenerator.invoke(any(), any(), any()) }.answers { "test" }

        Dispatchers.setMain(Dispatchers.Unconfined)

        val dateSelectedActionService = DateSelectedActionService(repository, viewModel)
        dateSelectedActionService.invoke(2020, 0, 22)

        verify(exactly = 1) { repository.findFirst(any()) }
        verify(exactly = 1) { viewModel.newArticle(any()) }
        verify(exactly = 1) { TitleFilterGenerator.invoke(any(), any(), any()) }
    }

}<commit_msg>refactor #580 Fix failing DateSelectedActionServiceTest.<commit_after>package jp.toastkid.article_viewer.calendar

import io.mockk.MockKAnnotations
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.mockkObject
import io.mockk.unmockkAll
import io.mockk.verify
import jp.toastkid.article_viewer.article.Article
import jp.toastkid.article_viewer.article.ArticleRepository
import jp.toastkid.lib.ContentViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.setMain
import org.junit.After
import org.junit.Before
import org.junit.Test

/**
 * @author toastkidjp
 */
class DateSelectedActionServiceTest {

    @MockK
    private lateinit var repository: ArticleRepository

    @MockK
    private lateinit var viewModel: ContentViewModel

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

    @ExperimentalCoroutinesApi
    @Test
    fun test() {
        every { repository.findFirst(any()) }.answers { Article(1).also { it.title = "test" } }
        every { viewModel.newArticle(any()) }.answers { Unit }

        mockkObject(TitleFilterGenerator)
        every { TitleFilterGenerator.invoke(any(), any(), any()) }.answers { "test" }

        Dispatchers.setMain(Dispatchers.Unconfined)

        val dateSelectedActionService = DateSelectedActionService(repository, viewModel)
        dateSelectedActionService.invoke(2020, 0, 22)
        Thread.sleep(1000L)

        verify(exactly = 1) { repository.findFirst(any()) }
        verify(exactly = 1) { viewModel.newArticle(any()) }
        verify(exactly = 1) { TitleFilterGenerator.invoke(any(), any(), any()) }
    }

    @After
    fun tearDown() {
        unmockkAll()
    }

}
{'fraction_non_alphanumeric': 0.10418548629930743, 'fraction_numerical': 0.008732309545317675, 'mean_word_length': 3.8496350364963505, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2148630', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1007, 'n_words': 189}