Search in sources :

Example 1 with ForwardingControllerListener

use of com.facebook.drawee.controller.ForwardingControllerListener in project fresco by facebook.

the class DraweeMocks method stubControllerListener.

/**
 * Stubs addControllerListener
 *
 * @param controller
 * @return forwarding listener
 */
public static ControllerListener stubControllerListener(final DraweeController controller) {
    final ForwardingControllerListener forwardingListener = new ForwardingControllerListener();
    if (!(controller instanceof AbstractDraweeController)) {
        return null;
    }
    AbstractDraweeController abstractController = (AbstractDraweeController) controller;
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            forwardingListener.addListener((ControllerListener) invocation.getArguments()[0]);
            return null;
        }
    }).when(abstractController).addControllerListener(any(ControllerListener.class));
    return forwardingListener;
}
Also used : Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ControllerListener(com.facebook.drawee.controller.ControllerListener) ForwardingControllerListener(com.facebook.drawee.controller.ForwardingControllerListener) ForwardingControllerListener(com.facebook.drawee.controller.ForwardingControllerListener) AbstractDraweeController(com.facebook.drawee.controller.AbstractDraweeController)

Aggregations

AbstractDraweeController (com.facebook.drawee.controller.AbstractDraweeController)1 ControllerListener (com.facebook.drawee.controller.ControllerListener)1 ForwardingControllerListener (com.facebook.drawee.controller.ForwardingControllerListener)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1