title: How to test function that observe live data
body: <p>Trying to write unit test on a function that observe livedata from the another class
  Could someone help me with it please.</p>
  <p>The class I'm trying to test:</p>
  <pre><code>override fun observe(activity: AppCompatActivity) {
      appCoordinatorManager.getState().observe(activity) {
          when(it) {
              is AppCoordinatorManager.State.AssociateWithReferralProgramSuccess -&gt; {
                  navigator.navigateToDashboard(null)
              }
  }
  </code></pre>
  <p>AppCoordinatorManager.getState()</p>
  <pre><code>private val state = LiveEvent&lt;State&gt;()
  
  fun getState(): LiveData&lt;State&gt; = state
  
  sealed class State {
      object AssociateWithReferralProgramSuccess: State()
  }
  </code></pre>
  <p>My test:</p>
  <pre><code>@Test
  fun `Receiving AssociateWithReferralProgramSuccess when observing state from AppCoordinatorManager`() {
  
      whenever(appCoordinatorManager.getState()).thenReturn(LiveEvent&lt;AppCoordinatorManager.State&gt;())
      
      appCoordinator.observe(activity)
  
      appCoordinatorManager.setPrivateField(&quot;state&quot;, LiveEvent&lt;AppCoordinatorManager.State.AssociateWithReferralProgramSuccess&gt;())
  
      verify(navigator).navigateToDashboard(null)
  }
  </code></pre>