Search in sources :

Example 1 with DraweeHierarchy

use of com.facebook.drawee.interfaces.DraweeHierarchy in project fresco by facebook.

the class DraweeMocks method stubGetAndSetHierarchy.

/**
 * Stubs setHierarchy and getHierarchy methods.
 *
 * @param controller controller to stub methods of
 */
public static void stubGetAndSetHierarchy(DraweeController controller) {
    final DraweeHierarchy[] dhHolder = new DraweeHierarchy[1];
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return dhHolder[0];
        }
    }).when(controller).getHierarchy();
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return dhHolder[0] = (DraweeHierarchy) invocation.getArguments()[0];
        }
    }).when(controller).setHierarchy((DraweeHierarchy) any());
}
Also used : Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) GenericDraweeHierarchy(com.facebook.drawee.generic.GenericDraweeHierarchy) DraweeHierarchy(com.facebook.drawee.interfaces.DraweeHierarchy)

Example 2 with DraweeHierarchy

use of com.facebook.drawee.interfaces.DraweeHierarchy in project fresco by facebook.

the class DraweeHolderTest method testTouchEventWithInvalidController.

@Test
public void testTouchEventWithInvalidController() {
    final DraweeHierarchy draweeHierarchy2 = DraweeMocks.mockDraweeHierarchyOf(mTopLevelDrawable);
    final DraweeHolder draweeHolder2 = new DraweeHolder(draweeHierarchy2);
    mDraweeHolder.setController(mController);
    draweeHolder2.setController(mController);
    mDraweeHolder.onTouchEvent(mock(MotionEvent.class));
    verify(mController, never()).onTouchEvent(any(MotionEvent.class));
}
Also used : DraweeHierarchy(com.facebook.drawee.interfaces.DraweeHierarchy) MotionEvent(android.view.MotionEvent) Test(org.junit.Test)

Example 3 with DraweeHierarchy

use of com.facebook.drawee.interfaces.DraweeHierarchy in project fresco by facebook.

the class DraweeHolderTest method testOverrideControllerHierarchy.

@Test
public void testOverrideControllerHierarchy() {
    DraweeHierarchy otherHierarchy = mock(DraweeHierarchy.class);
    mController.setHierarchy(otherHierarchy);
    assertSame(otherHierarchy, mController.getHierarchy());
    mDraweeHolder.setController(mController);
    assertSame(mController, mDraweeHolder.getController());
    assertSame(mDraweeHierarchy, mDraweeHolder.getHierarchy());
    assertSame(mDraweeHierarchy, mController.getHierarchy());
}
Also used : DraweeHierarchy(com.facebook.drawee.interfaces.DraweeHierarchy) Test(org.junit.Test)

Example 4 with DraweeHierarchy

use of com.facebook.drawee.interfaces.DraweeHierarchy in project fresco by facebook.

the class DraweeHolderTest method testSetNewControllerWithInvalidController.

@Test
public void testSetNewControllerWithInvalidController() {
    final DraweeHierarchy draweeHierarchy2 = DraweeMocks.mockDraweeHierarchyOf(mTopLevelDrawable);
    final DraweeHolder draweeHolder2 = new DraweeHolder(draweeHierarchy2);
    mDraweeHolder.onAttach();
    mDraweeHolder.setController(mController);
    draweeHolder2.setController(mController);
    mDraweeHolder.setController(null);
    verify(mController, never()).onDetach();
    assertEquals(draweeHierarchy2, mController.getHierarchy());
}
Also used : DraweeHierarchy(com.facebook.drawee.interfaces.DraweeHierarchy) Test(org.junit.Test)

Example 5 with DraweeHierarchy

use of com.facebook.drawee.interfaces.DraweeHierarchy in project fresco by facebook.

the class DraweeHolderTest method testOnDetachWithInvalidController.

@Test
public void testOnDetachWithInvalidController() {
    final DraweeHierarchy draweeHierarchy2 = DraweeMocks.mockDraweeHierarchyOf(mTopLevelDrawable);
    final DraweeHolder draweeHolder2 = new DraweeHolder(draweeHierarchy2);
    mDraweeHolder.onAttach();
    mDraweeHolder.setController(mController);
    draweeHolder2.setController(mController);
    mDraweeHolder.onDetach();
    verify(mController, never()).onDetach();
}
Also used : DraweeHierarchy(com.facebook.drawee.interfaces.DraweeHierarchy) Test(org.junit.Test)

Aggregations

DraweeHierarchy (com.facebook.drawee.interfaces.DraweeHierarchy)12 Test (org.junit.Test)6 GenericDraweeHierarchy (com.facebook.drawee.generic.GenericDraweeHierarchy)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Activity (android.app.Activity)1 Rect (android.graphics.Rect)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 MotionEvent (android.view.MotionEvent)1 ScaleTypeDrawable (com.facebook.drawee.drawable.ScaleTypeDrawable)1 ScaleType (com.facebook.drawee.drawable.ScalingUtils.ScaleType)1 GenericDraweeHierarchyBuilder (com.facebook.drawee.generic.GenericDraweeHierarchyBuilder)1 DraweeController (com.facebook.drawee.interfaces.DraweeController)1 SettableDraweeHierarchy (com.facebook.drawee.interfaces.SettableDraweeHierarchy)1 DraweeSpanStringBuilder (com.facebook.drawee.span.DraweeSpanStringBuilder)1 Before (org.junit.Before)1 Answer (org.mockito.stubbing.Answer)1