У меня есть следующий код внутри докладчика.
public class SignUpPresenter implements Presenter {
private CompositeDisposable disposables;
private View view;
@Inject public SignUpPresenter() {
}
public void setView(View view) {
this.view = view;
}
public void redirectToLogInScreenAfterOneSecond() {
disposables = RxUtil.initDisposables(disposables);
view.displaySuccessMessage();
Disposable disposable = Flowable.interval(1, TimeUnit.SECONDS)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(aLong -> view.onRegistrationSuccessful(), view::handleError);
disposables.add(disposable);
}
@Override public void dispose() {
RxUtil.dispose(disposables);
}
public interface View extends Presenter.View {
void onRegistrationSuccessful();
void displaySuccessMessage();
}
}
Теперь я хочу написать модульный тест для этого метода.
@RunWith(PowerMockRunner.class)
public class SignUpPresenterTest {
@Rule TrampolineSchedulerRule trampolineSchedulerRule = new TrampolineSchedulerRule();
@Mock SignUpPresenter.View view;
private SignUpPresenter presenter;
private TestScheduler testScheduler;
@Before public void setUp() {
testScheduler = new TestScheduler();
RxJavaPlugins.setComputationSchedulerHandler(scheduler -> testScheduler);
presenter = new SignUpPresenter();
presenter.setView(view);
}
@Test public void shouldDisplaySuccessMessage() {
testScheduler.advanceTimeTo(1, TimeUnit.SECONDS);
presenter.redirectToLogInScreenAfterOneSecond();
Mockito.verify(view).displaySuccessMessage();
Mockito.verify(view).onRegistrationSuccessful();
}
}
Вот ошибка, которую я получаю:
Wanted but not invoked:
view.onRegistrationSuccessful();
-> at com.test.presentation.signup.SignUpPresenterTest.shouldDisplaySuccessMessage(SignUpPresenterTest.java:36)
However, there were other interactions with this mock:
view.displaySuccessMessage();
-> at com.test.presentation.signup.SignUpPresenter.redirectToLogInScreenAfterOneSecond(SignUpPresenter.java:28)
Wanted but not invoked:
view.onRegistrationSuccessful();
-> at com.test.presentation.signup.SignUpPresenterTest.shouldDisplaySuccessMessage(SignUpPresenterTest.java:36)
However, there were other interactions with this mock:
view.displaySuccessMessage();
-> at com.test.presentation.signup.SignUpPresenter.redirectToLogInScreenAfterOneSecond(SignUpPresenter.java:28)
Как мне решить эту проблему?