Presenter { public final void takeView(V view) { if (view == null) throw new NullPointerException("new view must not be null"); if (this.view != view) { if (this.view != null) dropView(this.view); this.view = view; extractBundleService(view).register(registration); } }  final void takeView(V view); void dropView(V view);  }
@Test public void onLoadOnlyOncePerView() { SimplePresenter presenter = new SimplePresenter(); SomeView view = new SomeView(); presenter.takeView(view); assertThat(presenter.loaded).isTrue(); presenter.loaded = false; BundleServiceRunner.getBundleServiceRunner(activityScope).onCreate(null); assertThat(presenter.loaded).isFalse(); }
@Test public void newViewNewLoad() { SimplePresenter presenter = new SimplePresenter(); SomeView viewOne = new SomeView(); presenter.takeView(viewOne); assertThat(presenter.loaded).isTrue(); presenter.loaded = false; SomeView viewTwo = new SomeView(); presenter.takeView(viewTwo); assertThat(presenter.loaded).isTrue(); }
@Test public void autoDropCallsDrop() { SimplePresenter presenter = new SimplePresenter(); SomeView viewOne = new SomeView(); SomeView viewTwo = new SomeView(); presenter.takeView(viewOne); presenter.takeView(viewTwo); assertThat(presenter.droppedView).isSameAs(viewOne); }
@Test public void onRegisteredIsFired() { SimplePresenter presenter = new SimplePresenter(); SomeView viewOne = new SomeView(); presenter.takeView(viewOne); assertThat(presenter.registered).isSameAs(activityScope); }
@Test public void onExitIsFired() { SimplePresenter presenter = new SimplePresenter(); SomeView viewOne = new SomeView(); presenter.takeView(viewOne); activityScope.destroy(); assertThat(presenter.destroyed).isSameAs(activityScope); }