MvpNullObjectBasePresenter implements MvpPresenter<V> { @UiThread @NonNull protected V getView() { if (!viewAttachedAtLeastOnce) { throw new IllegalStateException("No view has ever been attached to this presenter!"); } if (view != null) { V realView = view.get(); if (realView != null) { return realView; } } return nullView; } MvpNullObjectBasePresenter(); @UiThread @Override void attachView(@NonNull V view); @Override @UiThread void detachView(); @Override @UiThread void destroy(); @Deprecated @UiThread @Override void detachView(boolean retainInstance);  }
@Test public void throwsExceptionWhenInteractingWithPresenterButNoViewHasEverAttached() { MvpNullObjectBasePresenter<MvpView> presenter = new MvpNullObjectBasePresenter<MvpView>() { }; try { presenter.getView(); Assert.fail("Exception should be thrown"); } catch (IllegalStateException e) { } }