BlueTapeDsl { public static BindingFunction id(int id, @NonNull BindingFunction... functions) { return view -> { View subView = view.findViewById(id); if (subView == null) { throw new ViewNotFoundException("View with id " + id + " cannot be found"); } composite(functions).bind(subView); }; }  static BindingFunction composite(@NonNull BindingFunction... functions); static BindingFunction id(int id, @NonNull BindingFunction... functions); static BindingFunction text(String text); static BindingFunction textResource(@StringRes int stringId); static BindingFunction textColor(@ColorInt int color); static BindingFunction visible(boolean visible); static BindingFunction visibility(@Visibility int visibility); static BindingFunction enabled(boolean enabled); static BindingFunction checked(boolean checked); static BindingFunction imageDrawable(@Nullable Drawable drawable); static BindingFunction imageResource(@DrawableRes int drawableId); static BindingFunction imageBitmap(@Nullable Bitmap bitmap); @SuppressWarnings("deprecation") static BindingFunction backgroundDrawable(@Nullable Drawable drawable); static BindingFunction backgroundResource(@DrawableRes int drawableId); static BindingFunction onClick(@Nullable View.OnClickListener listener); static BindingFunction onClick(@Nullable ShortenedOnClickListener listener); static BindingFunction onLongClick(@Nullable View.OnLongClickListener listener); static BindingFunction onTouch(@Nullable View.OnTouchListener listener); static BindingFunction onToggle(@Nullable CompoundButton.OnCheckedChangeListener listener); static BindingFunction onTextChanged(@Nullable OnTextChangedListener listener); static BindingFunction pass();  }
@Test public void id() throws Exception { int subViewId = 123; View subView = mock(View.class); given(view.findViewById(subViewId)) .willReturn(subView); BlueTapeDsl .id(subViewId, functionA, functionB ) .bind(view); InOrder inOrder = inOrder(functionA, functionB); inOrder.verify(functionA).bind(subView); inOrder.verify(functionB).bind(subView); }
@Test(expected = ViewNotFoundException.class) public void id_ViewNotFound() throws Exception { int subViewId = 123; given(view.findViewById(subViewId)) .willReturn(null); BlueTapeDsl .id(subViewId, functionA, functionB ) .bind(view); }