<commit_before>package com.mvcoding.mvp

import com.nhaarman.mockitokotlin2.*
import io.reactivex.Observable
import io.reactivex.subjects.PublishSubject
import org.junit.Before
import org.junit.Test
import ro.kreator.aRandom


class RefreshableViewTest {

    val view = mock<ViewForTest>()
    val dataSource = mock<DataSource<String, String>>()
    val input by aRandom<String>()
    val data by aRandom<String>()

    val refreshSubject = PublishSubject.create<Unit>()

    interface ViewForTest : DataView<String>, RefreshableView

    @Before
    fun setUp() {
        whenever(dataSource.data(any())).thenReturn(Observable.just(data))
        whenever(view.refreshes()).thenReturn(refreshSubject)
    }

    @Test
    fun `refreshable refreshes data`() {
        Observable.just(input)
                .loadData(view, dataSource)
                .refreshable(view)
                .subscribe()

        verify(dataSource).data(input)
        verify(view).showData(data)

        refreshSubject.onNext(Unit)

        verify(dataSource, times(2)).data(input)
        verify(view, times(2)).showData(data)
    }
}<commit_msg>Isolated RefreshableView tests.<commit_after>package com.mvcoding.mvp

import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.whenever
import io.reactivex.observers.TestObserver
import io.reactivex.subjects.PublishSubject
import org.junit.Test


class RefreshableViewTest {

    @Test
    fun `refreshable resubscribes to observable again when view initiates a refresh`() {
        val view = mock<RefreshableView>()
        val refreshSubject = PublishSubject.create<Unit>()
        whenever(view.refreshes()).thenReturn(refreshSubject)
        val observable = O.just(1)
        val observer = TestObserver.create<Int>()

        observable.refreshable(view).subscribe(observer)
        refreshSubject.onNext(Unit)

        observer.assertValues(1, 1)
    }
}
{'fraction_non_alphanumeric': 0.10424305919329492, 'fraction_numerical': 0.0041906757464641176, 'mean_word_length': 3.4212962962962963, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '7246099', 'n_tokens_mistral': 586, 'n_tokens_neox': 558, 'n_words': 105}