@Test
public void containsStream_unregistersListenerOnUnsubscribe() {

    final String testKey = "Test contains key";
    when(mockSharedPreferences.contains(testKey)).thenReturn(true);
    final TestObserver<Boolean> subscription = rxPreferences.containsStream(testKey).test();
    subscriptions.add(subscription);
    final ArgumentCaptor<SharedPreferences.OnSharedPreferenceChangeListener> listenerCaptor =
            ArgumentCaptor.forClass(SharedPreferences.OnSharedPreferenceChangeListener.class);
    verify(mockSharedPreferences).registerOnSharedPreferenceChangeListener(listenerCaptor.capture());
    final SharedPreferences.OnSharedPreferenceChangeListener listener = listenerCaptor.getValue();
    verify(mockSharedPreferences, never()).unregisterOnSharedPreferenceChangeListener(any());
    subscription.dispose();
    verify(mockSharedPreferences).unregisterOnSharedPreferenceChangeListener(listener);
}