Robolectric Test does not call textWatcher.onTextChanged

I have the following observed

Observable<OnTextChangeEvent> subjectObservable = WidgetObservable.text(mComposeSubject);

What then does

subjectObservable.subscribe(s -> onTextChange(mComposeSubject, getString(R.string.blank_warning, mComposeSubject.getHint().toString())));

I also have the following Robolectric test

@Test
public void testOnTextChange_subjectChanged() {
    EmailActivity activity = spy(getActivity());
    activity.mComposeSubject.setText("test");

    assertThat(activity.mSubjectSubscription).isNotNull();
    verify(activity, times(1)).onTextChange(eq(activity.mComposeSubject), anyString());
}

This does not work with the Wanted error, but is not called. Does anyone have an idea of ​​why this would be? as far as I know, this uses a simple text observer, so should it just work?

+4
source share
2 answers

Curiously, I started the transfer of subscribers to another class, and then used Observable.just ("Test") to start the method by subscribing and checking its call.

+1
source

, Robolectric test TextWatcher.afterTextChanged

,

EditText nameText = (EditText) mParentView.findViewById(R.id.edit_name);
nameText.setText(accountName);
Shadows.shadowOf(nameText).getWatchers().get(0).afterTextChanged(null);

ShadowTextView.getWatchers, , afterTextChanged ( onTextChange)

+1

All Articles