public static void stubSetVisibilityCallback(final Drawable drawable) {
    final AtomicBoolean isVisible = new AtomicBoolean(true);
    final AtomicReference<VisibilityCallback> callback = new AtomicReference<VisibilityCallback>();
    if (!(drawable instanceof VisibilityAwareDrawable)) {
      return;
    }
    VisibilityAwareDrawable visibilityAwareDrawable = (VisibilityAwareDrawable) drawable;
    doAnswer(
            new Answer<Void>() {
              @Override
              public Void answer(InvocationOnMock invocation) throws Throwable {
                callback.set((VisibilityCallback) invocation.getArguments()[0]);
                return null;
              }
            })
        .when(visibilityAwareDrawable)
        .setVisibilityCallback(any(VisibilityCallback.class));
    doAnswer(
            new Answer<Boolean>() {
              @Override
              public Boolean answer(InvocationOnMock invocation) throws Throwable {
                boolean initialValue = isVisible.get();
                boolean newValue = (Boolean) invocation.getArguments()[0];
                if (callback.get() != null) {
                  isVisible.set(newValue);
                  callback.get().onVisibilityChange(isVisible.get());
                }
                return initialValue != newValue;
              }
            })
        .when(drawable)
        .setVisible(anyBoolean(), anyBoolean());
    doAnswer(
            new Answer<Boolean>() {
              @Override
              public Boolean answer(InvocationOnMock invocation) throws Throwable {
                return isVisible.get();
              }
            })
        .when(drawable)
        .isVisible();
    doAnswer(
            new Answer<Void>() {
              @Override
              public Void answer(InvocationOnMock invocation) throws Throwable {
                if (callback.get() != null) {
                  callback.get().onDraw();
                }
                return null;
              }
            })
        .when(drawable)
        .draw(any(Canvas.class));
  }
Stubs setVisibilityCallback methods.

@param drawable drawable to stub methods of
drawee/src/test/java/com/facebook/drawee/drawable/DrawableTestUtils.java