DefaultDimensionResourceProvider implements IDimensionResourceProvider { @Override public int getDimensionInPixel(@DimenRes final int dimenRes) { return mContext.getResources().getDimensionPixelSize(dimenRes); } DefaultDimensionResourceProvider(final Context context); @Override int getDimensionInPixel(@DimenRes final int dimenRes);  }
@Test public void getDimensionInPixelTest() throws Exception { when(mMockContext.getResources()).thenReturn(mMockedResources); when(mMockedResources.getDimensionPixelSize(MOCKED_DIMEN_RES)).thenReturn(MOCKED_PIXEL_DIMEN); assert (mDimensionResourceProvider.getDimensionInPixel(MOCKED_DIMEN_RES) == MOCKED_PIXEL_DIMEN); verify(mMockContext, times(1)).getResources(); verify(mMockedResources, times(1)).getDimensionPixelSize(anyInt()); verifyNoMoreInteractions(mMockContext); verifyNoMoreInteractions(mMockedResources); }
@Test public void getDimensionInPixelFailTest() throws Exception { when(mMockContext.getResources()).thenReturn(mMockedResources); when(mMockedResources.getDimensionPixelSize(MOCKED_DIMEN_RES)).thenReturn(MOCKED_PIXEL_DIMEN); assert (mDimensionResourceProvider.getDimensionInPixel(MOCKED_DIMEN_RES) != 100); verify(mMockContext, times(1)).getResources(); verify(mMockedResources, times(1)).getDimensionPixelSize(anyInt()); verifyNoMoreInteractions(mMockContext); verifyNoMoreInteractions(mMockedResources); }