<commit_before>package com.felipecosta.kotlinrxjavasample.modules.listing.view

import android.support.v7.widget.RecyclerView
import com.felipecosta.kotlinrxjavasample.R
import com.felipecosta.kotlinrxjavasample.modules.listing.presentation.CharacterItemViewModel
import com.felipecosta.kotlinrxjavasample.modules.listing.presentation.CharacterListViewModel
import com.felipecosta.kotlinrxjavasample.util.bindView
import io.mockk.every
import io.mockk.mockk
import io.reactivex.subjects.BehaviorSubject.createDefault
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.robolectric.shadows.support.v4.SupportFragmentTestUtil.startFragment
import kotlin.test.assertEquals

@RunWith(RobolectricTestRunner::class)
@Config(application = TestStubApplication::class)
class CharacterListingFragmentTest {

    private val mockViewModel = mockk<CharacterListViewModel>(relaxed = true)

    private val items = listOf(CharacterItemViewModel(
            1,
            "Thor",
            "http://i.annihil.us/u/prod/marvel/i/mg/d/d0/5269657a74350.jpg"))

    @Test
    fun givenItemsEmittedWhenStartFragmentItShouldPopulateTheList() {
        val fragment = CharacterListingFragment()
        fragment.viewModel = mockViewModel
        createDefault(items).apply {
            every { mockViewModel.items } returns this
        }

        startFragment(fragment)

        val recyclerView: RecyclerView by fragment.bindView(R.id.listing_recycler_view)
        assertEquals(1, recyclerView.adapter.itemCount)
    }
}<commit_msg>Test swipe refresh on CharacterListingFragment<commit_after>package com.felipecosta.kotlinrxjavasample.modules.listing.view

import android.support.v4.widget.SwipeRefreshLayout
import android.support.v7.widget.RecyclerView
import com.felipecosta.kotlinrxjavasample.R
import com.felipecosta.kotlinrxjavasample.modules.listing.presentation.CharacterItemViewModel
import com.felipecosta.kotlinrxjavasample.modules.listing.presentation.CharacterListViewModel
import com.felipecosta.kotlinrxjavasample.util.bindView
import io.mockk.every
import io.mockk.mockk
import io.reactivex.Observable
import io.reactivex.subjects.BehaviorSubject.createDefault
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.robolectric.shadows.support.v4.SupportFragmentTestUtil.startFragment
import kotlin.test.assertEquals
import kotlin.test.assertTrue

@RunWith(RobolectricTestRunner::class)
@Config(application = TestStubApplication::class)
class CharacterListingFragmentTest {

    private val mockViewModel = mockk<CharacterListViewModel>(relaxed = true)

    private val items = listOf(CharacterItemViewModel(
            1,
            "Thor",
            "http://i.annihil.us/u/prod/marvel/i/mg/d/d0/5269657a74350.jpg"))

    @Test
    fun givenItemsEmittedWhenStartFragmentItShouldPopulateTheList() {
        val fragment = CharacterListingFragment()
        fragment.viewModel = mockViewModel
        createDefault(items).apply {
            every { mockViewModel.items } returns this
        }

        startFragment(fragment)

        val recyclerView: RecyclerView by fragment.bindView(R.id.listing_recycler_view)
        assertEquals(1, recyclerView.adapter.itemCount)
    }

    @Test
    fun givenShowLoadingEmittedWhenStartFragmentItShouldShowSwipeRefresh() {
        val fragment = CharacterListingFragment()
        fragment.viewModel = mockViewModel
        createDefault(items).apply {
            every { mockViewModel.showLoading } returns Observable.just(true)
        }

        startFragment(fragment)

        val swipeRefresh: SwipeRefreshLayout by fragment.bindView(R.id.listing_swipe_refresh)

        assertTrue { swipeRefresh.isRefreshing }
    }
}
{'fraction_non_alphanumeric': 0.07855297157622738, 'fraction_numerical': 0.00904392764857881, 'mean_word_length': 4.406424581005586, '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': '6546864', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1104, 'n_words': 167}