DataBindingLayoutPresenters { @SuppressWarnings("unchecked") @NonNull public static Builder dataBindingLayoutPresenterFor(@LayoutRes final int layoutId) { return new Builder(layoutId); } private  DataBindingLayoutPresenters(); @SuppressWarnings("unchecked") @NonNull static Builder dataBindingLayoutPresenterFor(@LayoutRes final int layoutId);  }
@Test public void shouldReturnLayoutForLayoutResId() { final LayoutPresenter layoutPresenter = dataBindingLayoutPresenterFor(LAYOUT_ID) .onRecycle(CLEAR_ITEM) .build(); assertThat(layoutPresenter.getLayoutResId(), is(LAYOUT_ID)); }
@Test public void shouldDoNothingWithLayoutPresenterOnRecycleItemOnlyRecycling() { final LayoutPresenter layoutPresenter = dataBindingLayoutPresenterFor(LAYOUT_ID) .handler(HANDLER_ID, HANDLER) .handler(SECOND_HANDLER_ID, SECOND_HANDLER) .onRecycle(CLEAR_ITEM) .build(); layoutPresenter.recycle(view); verifyZeroInteractions(viewDataBinding); }
@Test public void shouldRecycleLayoutPresenterWithAllRecycling() { final LayoutPresenter layoutPresenter = dataBindingLayoutPresenterFor(LAYOUT_ID) .handler(HANDLER_ID, HANDLER) .handler(SECOND_HANDLER_ID, SECOND_HANDLER) .onRecycle(CLEAR_ALL) .build(); layoutPresenter.recycle(view); verify(viewDataBinding).setVariable(HANDLER_ID, null); verify(viewDataBinding).setVariable(SECOND_HANDLER_ID, null); verify(viewDataBinding).executePendingBindings(); verifyNoMoreInteractions(viewDataBinding); }
@Test public void shouldRecycleLayoutPresenterWithHandlerRecycling() { final LayoutPresenter layoutPresenter = dataBindingLayoutPresenterFor(LAYOUT_ID) .handler(HANDLER_ID, HANDLER) .handler(SECOND_HANDLER_ID, SECOND_HANDLER) .onRecycle(CLEAR_HANDLERS) .build(); layoutPresenter.recycle(view); verify(viewDataBinding).setVariable(HANDLER_ID, null); verify(viewDataBinding).setVariable(SECOND_HANDLER_ID, null); verify(viewDataBinding).executePendingBindings(); verifyNoMoreInteractions(viewDataBinding); }
@Test public void shouldBindLayoutPresenter() { final LayoutPresenter layoutPresenter = dataBindingLayoutPresenterFor(LAYOUT_ID) .handler(HANDLER_ID, HANDLER) .handler(SECOND_HANDLER_ID, SECOND_HANDLER) .build(); layoutPresenter.bind(view); verify(viewDataBinding).setVariable(HANDLER_ID, HANDLER); verify(viewDataBinding).setVariable(SECOND_HANDLER_ID, SECOND_HANDLER); verify(viewDataBinding).executePendingBindings(); verifyNoMoreInteractions(viewDataBinding); }