### Question:
DiffItemPresenter { @PreDestroy public void preDestroy() { if (ready && open) { closeContent(); } } @Inject  DiffItemPresenter(final View view,
                             final ResourceTypeManagerCache resourceTypeManagerCache,
                             final PlaceManager placeManager,
                             final TranslationService ts); @PostConstruct void postConstruct(); @PreDestroy void preDestroy(); View getView(); void setup(final ChangeRequestDiff changeRequestDiff,
                      final boolean warnConflict); void draw(); void toggleCollapsibleContainerState();  }### Answer:
@Test public void preDestroyTextualDiffTest() throws NoSuchFieldException { new FieldSetter(presenter, DiffItemPresenter.class.getDeclaredField("ready")).set(true); new FieldSetter(presenter, DiffItemPresenter.class.getDeclaredField("open")).set(true); new FieldSetter(presenter, DiffItemPresenter.class.getDeclaredField("diffMode")).set(DiffMode.TEXTUAL); presenter.preDestroy(); verify(placeManager, never()).closePlace(any(PlaceRequest.class)); verify(view).removeTextualContent(); }
@Test public void preDestroyVisualDiffTest() throws NoSuchFieldException { new FieldSetter(presenter, DiffItemPresenter.class.getDeclaredField("diffMode")).set(DiffMode.VISUAL); new FieldSetter(presenter, DiffItemPresenter.class.getDeclaredField("placeRequestCustomLeft")) .set(mock(PlaceRequest.class)); new FieldSetter(presenter, DiffItemPresenter.class.getDeclaredField("placeRequestCustomRight")) .set(mock(PlaceRequest.class)); new FieldSetter(presenter, DiffItemPresenter.class.getDeclaredField("ready")).set(true); new FieldSetter(presenter, DiffItemPresenter.class.getDeclaredField("open")).set(true); presenter.preDestroy(); verify(placeManager, times(2)).closePlace(any(PlaceRequest.class)); }
@Test public void preDestroyVisualDiffOnlyLeftTest() throws NoSuchFieldException { new FieldSetter(presenter, DiffItemPresenter.class.getDeclaredField("diffMode")).set(DiffMode.VISUAL); new FieldSetter(presenter, DiffItemPresenter.class.getDeclaredField("placeRequestCustomLeft")) .set(mock(PlaceRequest.class)); new FieldSetter(presenter, DiffItemPresenter.class.getDeclaredField("ready")).set(true); new FieldSetter(presenter, DiffItemPresenter.class.getDeclaredField("open")).set(true); presenter.preDestroy(); verify(placeManager).closePlace(any(PlaceRequest.class)); }
@Test public void preDestroyVisualDiffOnlyRightTest() throws NoSuchFieldException { new FieldSetter(presenter, DiffItemPresenter.class.getDeclaredField("diffMode")).set(DiffMode.VISUAL); new FieldSetter(presenter, DiffItemPresenter.class.getDeclaredField("placeRequestCustomRight")) .set(mock(PlaceRequest.class)); new FieldSetter(presenter, DiffItemPresenter.class.getDeclaredField("ready")).set(true); new FieldSetter(presenter, DiffItemPresenter.class.getDeclaredField("open")).set(true); presenter.preDestroy(); verify(placeManager).closePlace(any(PlaceRequest.class)); }