title: How I can test what paged list return error during response?
body: <p>I am trying to test error in PagedList's data source (when load new group of data). My DataSource looks like that:</p>
  
  <pre><code>package com.ps.superheroapp.ui.character_screen.list
  
  import androidx.paging.PositionalDataSource
  import com.ps.superheroapp.api.MarvelApiService
  import com.ps.superheroapp.objects.SchedulerNames
  import io.reactivex.Scheduler
  import io.reactivex.disposables.CompositeDisposable
  import javax.inject.Named
  
  class CharactersDataSource(
      private val compositeDisposable: CompositeDisposable,
      private val marvelApi: MarvelApiService,
      @Named(SchedulerNames.MAIN) private val scheduler: Scheduler,
      private val filter: Filter
  ) : PositionalDataSource&lt;Character&gt;() {
  
      var events: SourcedDataEventsHandler? = null
  
      override fun loadInitial(params: LoadInitialParams, callback: LoadInitialCallback&lt;Character&gt;) {
          compositeDisposable.add(marvelApi.searchCharacter(params.pageSize, 0, filter.searchQuery)
              .observeOn(scheduler)
              .doOnSubscribe {
                  events?.onLoadStarted()
              }
              .subscribe({
                  callback.onResult(it.data.results ?: arrayListOf(), 0)
                  events?.onLoadFinishedSuccessfully()
              }, {
                  events?.onLoadFinishedWithError(it)
              })
          )
      }
  
      override fun loadRange(params: LoadRangeParams, callback: LoadRangeCallback&lt;Character&gt;) {
          compositeDisposable.add(
              marvelApi.searchCharacter(params.loadSize, params.startPosition, filter.searchQuery)
                  .observeOn(scheduler)
                  .doOnSubscribe {
                      events?.onLoadStarted()
                  }
                  .subscribe({
                      callback.onResult(it.data.results ?: arrayListOf())
                      events?.onLoadFinishedSuccessfully()
                  }, {
                      events?.onLoadFinishedWithError(it)
                  })
          )
      }
  }
  </code></pre>
  
  <p>If I will just mock events handler class and during test will call methods from it, this test will not test anything.</p>
  
  <p>I searched ways or best practice to test this type of behaviour but I didn't found something.</p>
  
  <p>My test looks like that:</p>
  
  <pre><code>@Test
  fun should_show_network_error_when_screen_data_cannot_be_loaded_because_of_internet_connection() {
  `when`(connectivityChecker.isOffline()).thenReturn(true)
      //logic to imitate error during loading from data source
  
      vm.fetchCharacters()
  
      Assert.assertEquals(ErrorType.NETWORK, vm.error.get())
  }
  </code></pre>
  
  <p>Could you please give me some advice or architectural example, or example of unit test to test this.
  Thanks in advance</p>