<commit_before>/*
 * Copyright (c) 2021 toastkidjp.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompany this distribution.
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html.
 */

package jp.toastkid.yobidashi.search.favorite

import android.content.Context
import io.mockk.MockKAnnotations
import io.mockk.Runs
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.just
import io.mockk.mockkConstructor
import io.mockk.mockkObject
import io.mockk.unmockkAll
import io.mockk.verify
import jp.toastkid.yobidashi.libs.Toaster
import jp.toastkid.yobidashi.libs.db.AppDatabase
import jp.toastkid.yobidashi.libs.db.DatabaseFinder
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import org.junit.After
import org.junit.Before
import org.junit.Test

class FavoriteSearchInsertionTest {

    private lateinit var favoriteSearchInsertion: FavoriteSearchInsertion

    @MockK
    private lateinit var appDatabase: AppDatabase

    @MockK
    private lateinit var repository: FavoriteSearchRepository

    @MockK
    private lateinit var context: Context

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

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

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

        every { context.getString(any(), any()) }.returns("test message")

        mockkConstructor(DatabaseFinder::class)
        every { anyConstructed<DatabaseFinder>().invoke(any()) }.returns(appDatabase)
        every { appDatabase.favoriteSearchRepository() }.returns(repository)
        every { repository.insert(any()) }.just(Runs)

        mockkObject(Toaster)
        every { Toaster.tShort(any(), any<String>()) }.answers { Unit }
    }

    @After
    fun tearDown() {
        unmockkAll()
    }

    @Test
    fun testInvoke() {
        favoriteSearchInsertion = FavoriteSearchInsertion(<commit_msg>refactor #412 Use just runs.<commit_after>/*
 * Copyright (c) 2021 toastkidjp.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompany this distribution.
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html.
 */

package jp.toastkid.yobidashi.search.favorite

import android.content.Context
import io.mockk.MockKAnnotations
import io.mockk.Runs
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.just
import io.mockk.mockkConstructor
import io.mockk.mockkObject
import io.mockk.unmockkAll
import io.mockk.verify
import jp.toastkid.yobidashi.libs.Toaster
import jp.toastkid.yobidashi.libs.db.AppDatabase
import jp.toastkid.yobidashi.libs.db.DatabaseFinder
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import org.junit.After
import org.junit.Before
import org.junit.Test

class FavoriteSearchInsertionTest {

    private lateinit var favoriteSearchInsertion: FavoriteSearchInsertion

    @MockK
    private lateinit var appDatabase: AppDatabase

    @MockK
    private lateinit var repository: FavoriteSearchRepository

    @MockK
    private lateinit var context: Context

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

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

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

        every { context.getString(any(), any()) }.returns("test message")

        mockkConstructor(DatabaseFinder::class)
        every { anyConstructed<DatabaseFinder>().invoke(any()) }.returns(appDatabase)
        every { appDatabase.favoriteSearchRepository() }.returns(repository)
        every { repository.insert(any()) }.just(Runs)

        mockkObject(Toaster)
        every { Toaster.tShort(any(), any<String>()) }.just(Runs)
    }

    @After
    fun tearDown() {
        unmockkAll()
    }

    @Test
    fun testInvoke() {
        favoriteSearchInsertion = FavoriteSearchInsertion(
{'fraction_non_alphanumeric': 0.08995080815179199, 'fraction_numerical': 0.004450691028343875, 'mean_word_length': 4.0294464075382805, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '537976', 'n_tokens_mistral': 1316, 'n_tokens_neox': 1269, 'n_words': 296}