title: What is the correct way to check the data from a PagingData object in Android Unit Tests
body: <p>I am using paging library to retrieve data from an api and show them in a list</p>
  <p>for this purpose in my repository I have created the method:</p>
  <p><code>fun getArticleList(query: String): Flow&lt;PagingData&lt;ArticleHeaderData&gt;&gt;</code></p>
  <p>in my viewmodel I have created the search method which goes something like this:</p>
  <pre><code>override fun search(query: String) {
      val lastResult = articleFlow
      if (query == lastQuery &amp;&amp; lastResult != null)
          return
      lastQuery = query
      searchJob?.cancel()
      searchJob = launch {
          val newResult: Flow&lt;PagingData&lt;ArticleList&gt;&gt; = repo.getArticleList(query)
              .map {
                  it.insertSeparators { //code to add separators }.cachedIn(this)
          articleFlow = newResult
          newResult.collectLatest {
              articleList.postValue(it)
          }
      }
  }
  </code></pre>
  <p>in order to test my viewmodel I am using the test method <code>PagingData.from</code> to create a flow to return from my mocked repository like so:</p>
  <p><code>whenever(repo.getArticleList(query)).thenReturn(flowOf(PagingData.from(articles)))</code></p>
  <p>and then I retrieve the actual paging data from the articleList LiveData like so:</p>
  <p><code>val data = vm.articleList.value!!</code></p>
  <p>this returns a <code>PagingData&lt;ArticleList&gt;</code> object that I would like to verify it contains the data from the service (i.e. the <code>articles</code> returned by whenever)</p>
  <p>the only way I have found to do this is by creating the following extension function:</p>
  <pre><code>private val dcb = object : DifferCallback {
      override fun onChanged(position: Int, count: Int) {}
      override fun onInserted(position: Int, count: Int) {}
      override fun onRemoved(position: Int, count: Int) {}
  }
  
  suspend fun &lt;T : Any&gt; PagingData&lt;T&gt;.collectData(): List&lt;T&gt; {
      val items = mutableListOf&lt;T&gt;()
      val dif = object : PagingDataDiffer&lt;T&gt;(dcb, TestDispatchers.Immediate) {
          override suspend fun presentNewList(previousList: NullPaddedList&lt;T&gt;, newList: NullPaddedList&lt;T&gt;, newCombinedLoadStates: CombinedLoadStates, lastAccessedIndex: Int): Int? {
              for (idx in 0 until newList.size)
                  items.add(newList.getFromStorage(idx))
              return null
          }
      }
      dif.collectFrom(this)
      return items
  }
  </code></pre>
  <p>which seems to work, but is based on the <code>PagingDataDiffer</code> class which is marked as <code>@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)</code> so it may not work in the future</p>
  <p>is there a better way to either get the <code>flow</code> from PagingData (which is marked as internal in the library) or get the actual data from it?</p>