<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.media.image.list

import io.mockk.MockKAnnotations
import io.mockk.Runs
import io.mockk.every
import io.mockk.impl.annotations.InjectMockKs
import io.mockk.impl.annotations.MockK
import io.mockk.just
import io.mockk.mockkConstructor
import io.mockk.spyk
import io.mockk.unmockkAll
import io.mockk.verify
import jp.toastkid.lib.preference.PreferenceApplier
import jp.toastkid.yobidashi.media.image.Image
import org.junit.After
import org.junit.Before
import org.junit.Test

class ImageLoaderUseCaseTest {

    @InjectMockKs
    private lateinit var imageLoaderUseCase: ImageLoaderUseCase

    @MockK
    private lateinit var preferenceApplier: PreferenceApplier

    @MockK
    private lateinit var adapter: Adapter

    @MockK
    private lateinit var bucketLoader: BucketLoader

    @MockK
    private lateinit var imageLoader: ImageLoader

    @MockK
    private lateinit var refreshContent: () -> Unit

    @MockK
    private lateinit var parentExtractor: ParentExtractor

    @Before
    fun setUp() {
        MockKAnnotations.init(this)
        every { adapter.clear() }.just(Runs)
        every { adapter.add(any()) }.just(Runs)
        every { refreshContent.invoke() }.just(Runs)
        every { preferenceApplier.excludedItems() }.returns(setOf("test"))
        every { preferenceApplier.imageViewerSort() }.returns("test")
        every { parentExtractor.invoke(any()) }.returns("to")

        val image = spyk(Image("/path/to/file", "name"))
        every { bucketLoader.invoke(any()) }.returns(listOf(image))
        every { imageLoader.invoke(any(), any()) }.returns(listOf(image))

        mockkConstructor(ExcludingItemFilter::class)
        every { anyConstructed<ExcludingItemFilter>().invoke(any()) }.returns(true)
    }

    @After
    fun tearDown() {
        unmockkAll()
    }

    @Test
    fun invoke() {
        imageLoaderUseCase.invoke()

        verify(exactly = 1) { adapter.clear() }
        verify(exactly = 1) { bucketLoader.invoke(any()) }
        verify(exactly = 0) { imageLoader.invoke(any(), any()) }
        verify(exactly = 1) { adapter.add(any()) }
    }

}<commit_msg>refactor #506 Rename test function.<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.media.image.list

import io.mockk.MockKAnnotations
import io.mockk.Runs
import io.mockk.every
import io.mockk.impl.annotations.InjectMockKs
import io.mockk.impl.annotations.MockK
import io.mockk.just
import io.mockk.mockkConstructor
import io.mockk.spyk
import io.mockk.unmockkAll
import io.mockk.verify
import jp.toastkid.lib.preference.PreferenceApplier
import jp.toastkid.yobidashi.media.image.Image
import org.junit.After
import org.junit.Before
import org.junit.Test

class ImageLoaderUseCaseTest {

    @InjectMockKs
    private lateinit var imageLoaderUseCase: ImageLoaderUseCase

    @MockK
    private lateinit var preferenceApplier: PreferenceApplier

    @MockK
    private lateinit var adapter: Adapter

    @MockK
    private lateinit var bucketLoader: BucketLoader

    @MockK
    private lateinit var imageLoader: ImageLoader

    @MockK
    private lateinit var refreshContent: () -> Unit

    @MockK
    private lateinit var parentExtractor: ParentExtractor

    @Before
    fun setUp() {
        MockKAnnotations.init(this)
        every { adapter.clear() }.just(Runs)
        every { adapter.add(any()) }.just(Runs)
        every { refreshContent.invoke() }.just(Runs)
        every { preferenceApplier.excludedItems() }.returns(setOf("test"))
        every { preferenceApplier.imageViewerSort() }.returns("test")
        every { parentExtractor.invoke(any()) }.returns("to")

        val image = spyk(Image("/path/to/file", "name"))
        every { bucketLoader.invoke(any()) }.returns(listOf(image))
        every { imageLoader.invoke(any(), any()) }.returns(listOf(image))

        mockkConstructor(ExcludingItemFilter::class)
        every { anyConstructed<ExcludingItemFilter>().invoke(any()) }.returns(true)
    }

    @After
    fun tearDown() {
        unmockkAll()
    }

    @Test
    fun testInvoke() {
        imageLoaderUseCase.invoke()

        verify(exactly = 1) { adapter.clear() }
        verify(exactly = 1) { bucketLoader.invoke(any()) }
        verify(exactly = 0) { imageLoader.invoke(any(), any()) }
        verify(exactly = 1) { adapter.add(any()) }
    }

}
{'fraction_non_alphanumeric': 0.11102139685102948, 'fraction_numerical': 0.005450141299959629, 'mean_word_length': 3.4399641577060933, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2657294', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1495, 'n_words': 348}