@Test
public void getAllStream_emitsOnListenerUpdate() {

    final Map<String, ?> returnedMap = Collections.singletonMap("Test dummy key", 234);
    //noinspection unchecked
    when(mockSharedPreferences.getAll()).thenReturn((Map) returnedMap);
    final TestObserver<Map<String, ?>> subscription = rxPreferences.getAllStream().test();
    subscriptions.add(subscription);
    subscription
            .assertNotComplete()
            .assertValueCount(1)
            .assertValue(returnedMap);
    final ArgumentCaptor<SharedPreferences.OnSharedPreferenceChangeListener> listenerCaptor =
            ArgumentCaptor.forClass(SharedPreferences.OnSharedPreferenceChangeListener.class);
    verify(mockSharedPreferences).registerOnSharedPreferenceChangeListener(listenerCaptor.capture());
    final SharedPreferences.OnSharedPreferenceChangeListener listener = listenerCaptor.getValue();
    listener.onSharedPreferenceChanged(mockSharedPreferences, "Another key");
    //noinspection unchecked
    subscription
            .assertNotComplete()
            .assertValueCount(2)
            .assertValues(returnedMap, returnedMap);
}