title: MediatorLiveData sources don't update during testing
body: <p>I have a <code>MediatorLiveData</code> living in my viewmodel that is supposed to react to <code>LiveData</code> emissions from the model layer, taking actions and updating its listeners when necessary. For some reason, the sources don't update during testing.</p>
  
  <pre><code>class MyViewModel(private val repository: Repository) : ViewModel() {
      private val liveData1: LiveData&lt;String&gt; = repository.getString1()
      private val livedata2: LiveData&lt;String&gt; = repository.getString2()
  
      val currentState = MediatorLiveData&lt;MyState&gt;
  
      init {
          currentState.addSource(liveData1) {
              it?.let { string1 -&gt;
                  doSomething()
                  currentState.postValue(String1Updated)
              }
          }
          currentState.addSource(liveData2) {
              it?.let { string1 -&gt;
                  doSomethingElse()
                  currentState.postValue(String2Updated)
              }
          }
      }
  }
  </code></pre>
  
  <p>Mocking an observer and the repository methods doesn't seem to help. <code>doSomething()</code> is never called, and currentState is not updated to String1Updated.</p>
  
  <pre><code>@RunWith(MockitoJUnitRunner::class)
  class MyViewModelTest {
      @get:Rule instantTaskExecutorRule = InstantTaskExecutorRule()
  
      @Mock lateinit var mockRepository: Repository
  
      @Mock lateinit var mockLiveData1: MutableLiveData&lt;String&gt;
  
      @Mock lateinit var mockLiveData2: MutableLiveData&lt;String&gt;
  
      @Mock lateinit var mockStateObserver: Observer&lt;MyState&gt;
  
      lateinit var myViewModel: MyViewModel
  
      @Before
      fun setup() {
          whenever(mockRepository.getLiveData1()).thenReturn(mockLiveData1)
          whenever(mockRepository.getLiveData2()).thenReturn(mockLiveData2)
  
          myViewModel = myViewModel(mockRepository)
      }
  
      @Test
      fun `Does something when live data 1 is updated`() {
          myViewModel.state.observeForever(mockStateObserver)
          mockLiveData1.postValue("hello world")
  
          verify(mockStateObserver).onChanged(String1Updated)
      }
  }
  </code></pre>
  
  <p>Even placing observers directly on <code>mockLiveData1</code> and <code>mockLiveData2</code> in addition to the observer on the mediator does not cause the sources to be updated in the mediator.</p>