MvpConductorLifecycleListener extends Controller.LifecycleListener { @Override public void preDestroyView(@NonNull Controller controller, @NonNull View view) { P presenter = getCallback().getPresenter(); if (presenter == null) { throw new NullPointerException( "Presenter returned from getPresenter() is null in " + callback); } presenter.detachView(); } MvpConductorLifecycleListener(MvpConductorDelegateCallback<V, P> callback); @Override void postCreateView(@NonNull Controller controller, @NonNull View view); @Override void preDestroyView(@NonNull Controller controller, @NonNull View view); @Override void postDestroy(@NonNull Controller controller);  }
@Test public void nullPointerExceptionGetPresenter() { MvpPresenter<MvpView> presenter = Mockito.mock(MvpPresenter.class); Controller controller = Mockito.mock(Controller.class); View view = Mockito.mock(View.class); MvpConductorDelegateCallback<MvpView, MvpPresenter<MvpView>> callback = Mockito.mock(MvpConductorDelegateCallback.class); MvpConductorLifecycleListener<MvpView, MvpPresenter<MvpView>> lifecycleListener = new MvpConductorLifecycleListener<>(callback); Mockito.when(callback.getPresenter()).thenReturn(null); try { lifecycleListener.preDestroyView(controller, view); Assert.fail(); } catch (NullPointerException e) { Assert.assertEquals(e.getMessage(), "Presenter returned from getPresenter() is null in " + callback); } }