Skip to content

Instantly share code, notes, and snippets.

@Gerlac
Gerlac / HomePresenter.kt
Created Nov 13, 2017
HomePresenter debounce operator
View HomePresenter.kt
searchTermUpdate
.debounce(DELAY_BETWEEN_SEARCH_TERM_REQUEST, TimeUnit.MILLISECONDS)
.switchMapSingle { searchTerm -> suggestionsRepository.getSearchTermSuggestions(searchTerm) }
.subscribe { suggestions -> view.showSearchSuggestions(suggestions) })
@Gerlac
Gerlac / HomePresenterTest.kt
Created Nov 12, 2017
Home presenter Test. Debounce Faiure
View HomePresenterTest.kt
@Test
fun onTextTyped_showSearchSuggestions() {
`when`(suggestionsRepository.getSearchTermSuggestions(ANY_SEARCH_TERM)).thenReturn(Single.just(ANY_SUGGESTIONS_LIST))
val presenter = createSUT()
presenter.onNewSearch(ANY_SEARCH_TERM)
verify(view).showSearchSuggestions(ANY_SUGGESTIONS_LIST)
}
@Gerlac
Gerlac / ComputationSchedulerTestRule.kt
Created Nov 12, 2017
ComputationSchedulerTestRule implementation
View ComputationSchedulerTestRule.kt
class ComputationSchedulerTestRule : TestRule {
val computationScheduler: TestScheduler = TestScheduler()
override fun apply(statement: Statement?, p1: Description?): Statement {
return object : Statement() {
@Throws(Throwable::class)
override fun evaluate() {
RxJavaPlugins.setComputationSchedulerHandler { computationScheduler }